next.js
next.js copied to clipboard
Router.replace with `as` parameter does not render the `url` page
Verify canary release
- [X] I verified that the issue exists in the latest Next.js canary release
Provide environment information
Operating System:
Platform: darwin
Arch: arm64
Version: Darwin Kernel Version 21.6.0: Mon Aug 22 20:19:52 PDT 2022; root:xnu-8020.140.49~2/RELEASE_ARM64_T6000
Binaries:
Node: 16.13.0
npm: 8.19.0
Yarn: 1.22.17
pnpm: 7.1.7
Relevant packages:
next: 12.2.6-canary.8
eslint-config-next: N/A
react: 18.1.0
react-dom: 18.1.0
Describe the Bug
I have a Next.js application with a dynamic route /[slug].js
When I do this inside the dynamic route:
router.replace("/404", router.asPath)
It keeps showing page contents of /[slug].js
and not the /404.js
page.
More details in minimal repro below:
Expected Behavior
For the 404 page to be shown.
Link to reproduction
https://router-bug-repro.vercel.app/
To Reproduce
Link to GH Repo: https://github.com/steven-tey/router-bug-repro
This app has a dynamic route /[slug].js
.
If you go to any of the following
- https://router-bug-repro.vercel.app/a
- https://router-bug-repro.vercel.app/b
- https://router-bug-repro.vercel.app/test
It should show their respective slug
values.
However, if you go to https://router-bug-repro.vercel.app/blocked (which is a blocked path), it shows blocked, instead of showing the contents on the default 404
page.
Just took a quick look at the repro and it looks like pages/404.js
isn't present so the router.replace
would need to point the url
to /_error
instead. I did a test with pages/404
present and it appears to be working correctly here https://router-bug-repro-4bozmev4p-ijjk-testing.vercel.app/blocked
This closed issue has been automatically locked because it had no new activity for a month. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.