-
Notifications
You must be signed in to change notification settings - Fork 28.7k
Fix rewrite and dynamic params on navigating to initial history entry #25495
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
ijjk
merged 8 commits into
vercel:canary
from
PepijnSenders:feature/fix-rewrite-and-dynamic-params
Jun 1, 2021
Merged
Changes from 2 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
bd7a4b3
Fix rewrite and dynamic params
PepijnSenders 58ee309
Merge branch 'canary' into feature/fix-rewrite-and-dynamic-params
PepijnSenders 0503e34
Merge branch 'canary' into feature/fix-rewrite-and-dynamic-params
PepijnSenders 1e7d161
set _shouldResolveHref to true when initializing client state
PepijnSenders 57aca30
add window.beforeNav check
PepijnSenders 3a01bea
fix broken path
PepijnSenders 66cfd98
fix build-output tests
PepijnSenders 643e800
remove yarn.lock changes
PepijnSenders File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
10 changes: 10 additions & 0 deletions
10
test/integration/rewrite-with-browser-history/next.config.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
module.exports = { | ||
rewrites() { | ||
return [ | ||
{ | ||
source: '/:pagePrefix/:path*', | ||
destination: '/dynamic-page/:path*', | ||
}, | ||
] | ||
}, | ||
} |
23 changes: 23 additions & 0 deletions
23
test/integration/rewrite-with-browser-history/pages/dynamic-page/[[...param]].js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { useRouter } from 'next/router' | ||
import Link from 'next/link' | ||
|
||
export default function Page(props) { | ||
const router = useRouter() | ||
|
||
return ( | ||
<> | ||
<p id="another">another page</p> | ||
<p id="pathname">{router.pathname}</p> | ||
<p id="query">{JSON.stringify(router.query)}</p> | ||
|
||
<Link href="/" as="/"> | ||
<a id="to-index">Go back to index</a> | ||
</Link> | ||
<br /> | ||
</> | ||
) | ||
} | ||
|
||
export const getServerSideProps = () => { | ||
return { props: {} } | ||
} |
19 changes: 19 additions & 0 deletions
19
test/integration/rewrite-with-browser-history/pages/index.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { useRouter } from 'next/router' | ||
|
||
export default function Page() { | ||
const router = useRouter() | ||
|
||
return ( | ||
<> | ||
<p id="index">index page</p> | ||
<p id="pathname">{router.pathname}</p> | ||
<p id="query">{JSON.stringify(router.query)}</p> | ||
|
||
<br /> | ||
</> | ||
) | ||
} | ||
|
||
export const getServerSideProps = () => { | ||
return { props: {} } | ||
} |
58 changes: 58 additions & 0 deletions
58
test/integration/rewrite-with-browser-history/test/index.test.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/* eslint-env jest */ | ||
|
||
import { join } from 'path' | ||
import { | ||
findPort, | ||
killApp, | ||
launchApp, | ||
nextBuild, | ||
nextStart, | ||
} from 'next-test-utils' | ||
import webdriver from 'next-webdriver' | ||
|
||
jest.setTimeout(1000 * 60 * 2) | ||
|
||
const appDir = join(__dirname, '../') | ||
|
||
let appPort | ||
let app | ||
|
||
const runTests = () => { | ||
it('back-button should go back to rewritten path successfully', async () => { | ||
const browser = await webdriver(appPort, '/rewrite-me') | ||
|
||
expect(await browser.elementByCss('#another').text()).toBe('another page') | ||
|
||
await browser | ||
.elementByCss('#to-index') | ||
.click() | ||
.waitForElementByCss('#index') | ||
|
||
await browser.back() | ||
|
||
expect(await browser.elementByCss('#another').text()).toBe('another page') | ||
}) | ||
} | ||
|
||
describe('rewrites persist with browser history actions', () => { | ||
describe('dev mode', () => { | ||
beforeAll(async () => { | ||
appPort = await findPort() | ||
app = await launchApp(appDir, appPort) | ||
}) | ||
afterAll(() => killApp(app)) | ||
|
||
runTests() | ||
}) | ||
|
||
describe('production mode', () => { | ||
beforeAll(async () => { | ||
await nextBuild(appDir) | ||
appPort = await findPort() | ||
app = await nextStart(appDir, appPort) | ||
}) | ||
afterAll(() => killApp(app)) | ||
|
||
runTests() | ||
}) | ||
}) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is where it goes wrong I guess, the first param is not defined in the second path, and the
[[...param]]
then doesn't get defined and the router thinks it can't match the route.Before when we resolved the rewrites on these URL's it did work though because it will rematch this and figure out that the
[[...param]]
is actually in that URL.