Catch-all dynamic route doesn't catch a path with undefined path parameter
See original GitHub issueBug report
Describe the bug
Hello! I’m experiencing an issue with a dynamic catch-all route and empty path parameters. For example:
/pages/[...slug]/index.tsx
Is not catching the route: http://localhost:3000/empty//parameter
Instead, it is loading default 404 page.
To Reproduce
Steps to reproduce the behavior, please provide code snippets or a repository:
Create a simple catch-all page:
// /pages/[...slug]/index.js
export default function () {
return <div>{'Hello!'}</div>;
}
Then try to load URL with empty path parameter:
http://localhost:3000/empty//parameter
Expected behavior
It should load the catch-all page, not a 404.
System information
- OS: macOS
- Browser (if applies): Chrome
- Version of Next.js: 9.4.0
- Version of Node.js: 14.0.0
Issue Analytics
- State:
- Created 3 years ago
- Comments:9 (4 by maintainers)
Top Results From Across the Web
Vue Router - catch all wildcard not working - Stack Overflow
I'm trying to use dynamic route match, but when I set path: "/:user" , go to route /user1234 and try to get it...
Read more >Dynamic Routes Details - Next.js
Here is some essential information you should know about dynamic routes. ... Dynamic routes can be extended to catch all paths by adding...
Read more >Next.js Tutorial - 9 - Catch All Routes - YouTube
Courses - https://learn.codevolution.dev/⚡️ Checkout Taskade! https://www.taskade.com/ Support UPI - https://support.codevolution.dev/ ...
Read more >Client-Side Routing In Next.js - Smashing Magazine
next-app └── pages ├── index.js // path: base-url (/) └── home.js ... Extending Dynamic Route Segments With Catch All Routes #.
Read more >Implementing SSR in Next.js: Dynamic routing and prefetching
To get started, then, you should create all of your routes. ... Next.js doesn't allow you to pass undefined as a prop.
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
This comes down to the way Next.js handles matching routes.
It uses the
path-to-regexp
library to create Regexes which are then matched to the routes. For the catchall route,'/:path(.*)'
is passed as an argument to thepathToRegexp
function.And it behaves like this:
If you pass
'/:path(.*)'
instead, it can handle empty path parameters:Using
'/:path*'
(instead of'/:path(.*)'
) to match the catch-all routes is all over the Next.js codebase and I’m not sure if it’s intentional or not.If somebody from the Next.js team could tell if it’s intentional to NOT match routes with empty parameters it’d be awesome 😃
This issue has been automatically locked due to no recent activity. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.