Unverified Commit 75566114 authored by 유경화's avatar 유경화 Committed by GitHub

fix(next/router): Prevent query delete in routing when next.config basePath…

fix(next/router): Prevent query delete in routing when next.config basePath option is truthy (#40566)



## Bug

- [x] Related issues linked using `fixes #number`
    - fixes 
        - #38528 
        - #40432
- [x] Integration tests added
- [ ] Errors have helpful link attached, see `contributing.md`

Hi, it is my first pull request in this project.
So... if you need anything more tasks, please tell me.
Co-authored-by: 's avatarJJ Kasper <22380829+ijjk@users.noreply.github.com>
parent 40b2d138
......@@ -1552,7 +1552,11 @@ export default class Router implements BaseRouter {
query = Object.assign({}, routeInfo.query || {}, query)
}
if (routeMatch && pathname !== parsed.pathname) {
const cleanedParsedPathname = hasBasePath(parsed.pathname)
? removeBasePath(parsed.pathname)
: parsed.pathname
if (routeMatch && pathname !== cleanedParsedPathname) {
Object.keys(routeMatch).forEach((key) => {
if (routeMatch && query[key] === routeMatch[key]) {
delete query[key]
......
import { useRouter } from 'next/router'
export default function DynamicRoutes() {
const { query } = useRouter()
return (
<main>
<h1 id="route-name">{query.routeName}</h1>
</main>
)
}
......@@ -27,6 +27,11 @@ export default function Main({ message }) {
<a>redirect me to about</a>
</Link>
</li>
<li>
<Link href="/dynamic-routes/hello-world">
<a id="go-to-hello-world-anchor">Hello World</a>
</Link>
</li>
</ul>
</div>
)
......
......@@ -35,4 +35,14 @@ describe('Middleware base tests', () => {
const $ = cheerio.load(html)
expect($('.title').text()).toBe('About Page')
})
it('router.query must exist when Link clicked page routing', async () => {
const browser = await webdriver(next.url, '/root')
try {
await browser.elementById('go-to-hello-world-anchor').click()
const routeName = await browser.elementById('route-name').text()
expect(routeName).toMatch('hello-world')
} finally {
await browser.close()
}
})
})
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment