Both URLs /foo and /foo/ should render the contents of /pages/foo/index.js.
/foo works fine, but /foo/ causes a 404 error on SSR and only reconciles later at client side rendering.
export default () => <div>hello world</div>
| Tech | Version |
|---------|---------|
| next | 5.0.0 |
| node | 8.9.0 |
Fixed in next@canary
@timneutkens I can reproduce this bug in canary 6.0.0-6.
Unless I'm mistaken, I don't think this is fixed in 6.0.0-canary.6
. I've tried to produce a minimal example to demonstrate.
page | url | client | server
--|--|--|--
/pages/simple.js | /simple | ✅ | ✅
/pages/simple.js | /simple/ | ✅ | 404
/pages/nested/index.js | /nested | ✅ | ✅
/pages/nested/index.js | /nested/ | ✅ | 404
/pages/blog.js | /blog/first (parameterized route copied from example | ✅ | 404
It is my understanding that the last 2 - "/pages/nested/index.js" and "/pages/blog.js" should not 404 on the server.
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.
still not fix in next 6.x
This is fixed :tada:
https://zeit.co/blog/new-static-deployments
That's great but I believe that doesn't help non static deployments or apps not hosted with Now.
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 any status when this will be fixed for non-static deployments / static deployments hosted elsewhere?
I filed a new issue with minimal reproducible repository in #5214
If you want trailing slash, you can just do this. <Link href='/about' as='/about/'><a>about</a></Link>
but if you're using fridays/next-routes this is not possible. So I have a fork where you can add trailingSlash
as prop. Hope this helps!
This is still not working in [email protected]
/pages/nested/index.js | /nested/ | ✅ | 404
-- | -- | -- | --
That's great but I believe that doesn't help non static deployments or apps not hosted with Now.
Having this issue now
@reginpv what is your config in _next.config.js_?
For me setting _trailingSlash_ to _false_ made that work.
@Shaquu Looks like updating to latest fixed this for me, I'm not seeing the issue now. Will continue to monitor and if ever saw the issue again will report
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 Link
components.
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.
why this issue closed? anyone have a good advice for handle trailing slash
Most helpful comment
still not fix in next 6.x