Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit08dce4b

Browse files
authored
Ensure history navigates correctly with dynamic routes + basePath (vercel#25459)
This ensures the `basePath` is correctly re-added to the `url` after resolving a dynamic route since the `url` stored in history is expected to already contain the `basePath`, an additional test has been added to ensure this is working correctly back/forward through history## Bug- [x] Related issues linked using `fixes #number`- [x] Integration tests addedFixes:vercel#25285
1 parent3b9221f commit08dce4b

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

‎packages/next/next-server/lib/router/router.ts‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -993,14 +993,15 @@ export default class Router implements BaseRouter {
993993
// if this directly matches a page we need to update the href to
994994
// allow the correct page chunk to be loaded
995995
pathname=rewritesResult.resolvedHref
996-
parsed.pathname=pathname
996+
parsed.pathname=addBasePath(pathname)
997997
url=formatWithValidation(parsed)
998998
}
999999
}else{
10001000
parsed.pathname=resolveDynamicRoute(pathname,pages)
10011001

10021002
if(parsed.pathname!==pathname){
10031003
pathname=parsed.pathname
1004+
parsed.pathname=addBasePath(pathname)
10041005
url=formatWithValidation(parsed)
10051006
}
10061007
}
@@ -1529,6 +1530,7 @@ export default class Router implements BaseRouter {
15291530

15301531
if(parsed.pathname!==pathname){
15311532
pathname=parsed.pathname
1533+
parsed.pathname=pathname
15321534
url=formatWithValidation(parsed)
15331535
}
15341536
}

‎test/integration/basepath/test/index.test.js‎

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,32 @@ afterAll(async () => {
5454
})
5555

5656
construnTests=(dev=false)=>{
57+
it('should navigate back correctly to a dynamic route',async()=>{
58+
constbrowser=awaitwebdriver(appPort,`${basePath}`)
59+
60+
expect(awaitbrowser.elementByCss('#index-page').text()).toContain(
61+
'index page'
62+
)
63+
64+
awaitbrowser.eval('window.beforeNav = 1')
65+
66+
awaitbrowser.eval('window.next.router.push("/catchall/first")')
67+
awaitcheck(()=>browser.elementByCss('p').text(),/first/)
68+
expect(awaitbrowser.eval('window.beforeNav')).toBe(1)
69+
70+
awaitbrowser.eval('window.next.router.push("/catchall/second")')
71+
awaitcheck(()=>browser.elementByCss('p').text(),/second/)
72+
expect(awaitbrowser.eval('window.beforeNav')).toBe(1)
73+
74+
awaitbrowser.eval('window.next.router.back()')
75+
awaitcheck(()=>browser.elementByCss('p').text(),/first/)
76+
expect(awaitbrowser.eval('window.beforeNav')).toBe(1)
77+
78+
awaitbrowser.eval('window.history.forward()')
79+
awaitcheck(()=>browser.elementByCss('p').text(),/second/)
80+
expect(awaitbrowser.eval('window.beforeNav')).toBe(1)
81+
})
82+
5783
if(dev){
5884
describe('Hot Module Reloading',()=>{
5985
describe('delete a page and add it back',()=>{

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp