next.js: Routing error for urls with trailing slash since 5.0.0
- [x ] I have searched the issues of this repository and believe that this is not a duplicate.
Expected Behavior
Both URLs /foo and /foo/ should render the contents of /pages/foo/index.js.
Current Behavior
/foo works fine, but /foo/ causes a 404 error on SSR and only reconciles later at client side rendering.
Steps to Reproduce (for bugs)
- create minimal next.js project
- create /pages/foo/index.js including e.g.
export default () => <div>hello world</div> - test url /foo/, should throw 404 on SSR
Context
Your Environment
| Tech | Version |
|---|---|
| next | 5.0.0 |
| node | 8.9.0 |
About this issue
- Original URL
- State: closed
- Created 9 years ago
- Reactions: 5
- Comments: 19 (7 by maintainers)
This is still not working in next@9.0.4
still not fix in next 6.x
Ah, good point on static apps hosted elsewhere. I’ve never had a trailing slash issue with dynamic deployments, so this fixes the problem for me and likely several other people.
@timneutkens I can reproduce this bug in canary 6.0.0-6.
@timneutkens any status when this will be fixed for non-static deployments / static deployments hosted elsewhere?
That’s great but I believe that doesn’t help non static deployments or apps not hosted with Now.
I am seeing the same issue now, but only when I refresh the page. It’s even funnier, because I am using a project template with TypeScript, that for some reason always adds a trailing slash to the paths defined in
Linkcomponents.For example: I write
Link href="/about", it gets changed to “/about/”. It works when I navigate, but then if I refresh the page, the route doesn’t match anymore the “about.tsx” page, or “about/index.tsx” (doesn’t make a difference). I don’t see the same issue when using the default starter template with ES.I can also confirm the bug. For my production site, I “fixed” it by redirecting urls with slashes to urls without them using this code in nginx config:
rewrite ^/(.*)/$ /$1 permanent;Not sure if redirects are possible on Now, I use a custom server.Fixed in
next@canary