allow manually redirecting to 404 route within a dynamic slug
See original GitHub issueEnvironment
------------------------------
- Operating System: `Linux`
- Node Version: `v16.14.2`
- Nuxt Version: `3.0.0-rc.1`
- Package Manager: `npm@7.17.0`
- Builder: `vite`
- User Config: `-`
- Runtime Modules: `-`
- Build Modules: `-`
------------------------------
Reproduction
https://stackblitz.com/edit/github-yyumyt?file=pages/404.vue
Describe the bug
I have defined three pages (routes):
car.vue
[slug].vue
404.vue
If I go to http://.../hi
=> it loads [slug].vue
=> OK
If I go to http://.../car
=> it loads car.vue
=> OK
If I go to http://.../404
=> it loads [slug].vue
=> FAIL
Additional context
No response
Logs
No response
Issue Analytics
- State:
- Created a year ago
- Reactions:4
- Comments:20 (10 by maintainers)
Top Results From Across the Web
Dynamic route prevents redirecting to 404 page in Next.js
js file inside /pages directory. If I delete my [pid].js file, 404 page works just fine. But, if I keep my [pid].
Read more >How to redirect to 404 when slug is invalid? : r/Nuxt - Reddit
Can anyone tell me how to manually redirect to a 404 from a dynamic route component where the incoming slug is deemed (by...
Read more >Empty page instead of 404 error when url contains channel slug
Whenever a wrong url is entered manually behind "example.com/news/" (or maybe a wrong filled in link) it won't go to the 404 page...
Read more >Shallow Routing - Next.js
Shallow routing allows you to change the URL without running data fetching methods again ... Shallow routing only works for URL changes in...
Read more >File System Routing - Nuxt
Thus 301 redirects should be in place and your internal linking has to be adapted correctly. If you set trailingSlash to true ,...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I am positive the broad idea of this issue is to ask “how to handle 404 on dynamic path”.
There is currently no documentation on how to properly handle API’s 404 response in the docs. From my experience it is also extremely hard, as all of the 4 navigation types listed in comments above require different logic each.
Here is the repo reproduction in case you want to bootstrap the project: data-fetching
Thanks for that link @Aareksio.
I’ve submitted a related PR to fix an issue, add some basic docs and improve DX (by avoiding import of
createError
), but check out https://stackblitz.com/edit/github-jwfbey. Does that answer your questions?