-
Notifications
You must be signed in to change notification settings - Fork 27k
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
Catch-all dynamic route doesn't catch a path with undefined path parameter #13011
Comments
This comes down to the way Next.js handles matching routes. It uses the And it behaves like this: const regex = path.pathToRegexp("/:path*");
console.log(regex.test("/catch/all/route")); // true
console.log(regex.test("/catch//route")); // false If you pass const regex = path.pathToRegexp("/:path(.*)");
console.log(regex.test("/catch/all/route")); // true
console.log(regex.test("/catch//route")); // true Using If somebody from the Next.js team could tell if it's intentional to NOT match routes with empty parameters it'd be awesome :) |
It sounds like Next.js should disallow multi-slash and auto-redirect. |
@tomdohnal thanks for looking into this. @Timer can you describe more what you mean by this? I'm unsure what you mean by multi-slash and auto-redirect, and also unsure if you want to disallow both of them, or rather disallow multi-slash but instead auto-redirect |
To clarify what I meant, Next.js should intercept any request with double forward slashes and normalize it to one with a redirect. |
Oh okay, cool, I think that could make sense. Do you think it's necessary to normalize and redirect? Would it be okay to leave it as an undefined path parameter, especially if we're using [...slug] catch-all? It might be valuable for the app to know if a certain parameter was undefined (as opposed to changing the number of parameters in the scenario of normalizing) |
Hello team 👋 It looks like you are going to be normalizing double slashes to a single slash. Will there be a way to opt out of this? I would like to be able to conserve the data of the empty param. So for my original example, with page:
and URL: http://localhost:3000/empty//parameter I'd like to have
I have legacy link structure that I need to be able to handle with catch-all route. My legacy link structure looks like: https://song.link/https://open.spotify.com/track/69o00fGvsei250jH7bF781 Do you know how I can handle this URL? |
Ah, I think I figured it out. I can define a rewrite:
Then in the API route I can grab Hopefully the work in #15171 won't conflict with this solution, but I don't think it will bc my |
@Timer @kweiberth So, the issue is, Can one of you or someone from next team give an explanation around this. |
This adds handling for repeated forward/back slashes in Next.js, when these slashes are detected in a request to Next.js we will automatically remove the additional slashes redirecting with a 308 status code which prevents duplicate content when being crawled by search engines. Fixes: #13011 Fixes: #23772 Closes: #15171 Closes: #25745
This adds handling for repeated forward/back slashes in Next.js, when these slashes are detected in a request to Next.js we will automatically remove the additional slashes redirecting with a 308 status code which prevents duplicate content when being crawled by search engines. Fixes: vercel#13011 Fixes: vercel#23772 Closes: vercel#15171 Closes: vercel#25745
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. |
Bug report
Describe the bug
Hello! I'm experiencing an issue with a dynamic catch-all route and empty path parameters. For example:
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:
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
The text was updated successfully, but these errors were encountered: