Skip to content
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

Routing error for urls with trailing slash since 5.0.0 #3876

Closed
hyperborea opened this issue Feb 23, 2018 · 19 comments
Closed

Routing error for urls with trailing slash since 5.0.0 #3876

hyperborea opened this issue Feb 23, 2018 · 19 comments

Comments

@hyperborea
Copy link

  • [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)

  1. create minimal next.js project
  2. create /pages/foo/index.js including e.g. export default () => <div>hello world</div>
  3. test url /foo/, should throw 404 on SSR

Context

Your Environment

Tech Version
next 5.0.0
node 8.9.0
@timneutkens
Copy link
Member

Fixed in next@canary

@fionawhim
Copy link
Contributor

@timneutkens I can reproduce this bug in canary 6.0.0-6.

@lkbr
Copy link

lkbr commented Apr 26, 2018

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.

@kheruc
Copy link
Contributor

kheruc commented Apr 26, 2018

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.

@mydearxym
Copy link

still not fix in next 6.x

@NathanielHill
Copy link
Contributor

This is fixed 🎉
https://zeit.co/blog/new-static-deployments

@lkbr
Copy link

lkbr commented Jun 14, 2018

That's great but I believe that doesn't help non static deployments or apps not hosted with Now.

@NathanielHill
Copy link
Contributor

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.

@eugeneross
Copy link

@timneutkens any status when this will be fixed for non-static deployments / static deployments hosted elsewhere?

@iamstarkov
Copy link

I filed a new issue with minimal reproducible repository in #5214

@aluminick
Copy link

aluminick commented Dec 10, 2018

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!

@aripekkako
Copy link

This is still not working in next@9.0.4

/pages/nested/index.js /nested/ 404

mattwagl pushed a commit to thenativeweb/wolkenkit that referenced this issue Sep 6, 2019
See also this issue with Routing errors and trailing slashes vercel/next.js#3876
@reginpv
Copy link

reginpv commented Dec 19, 2019

That's great but I believe that doesn't help non static deployments or apps not hosted with Now.

Having this issue now

@Shaquu
Copy link

Shaquu commented Jan 7, 2020

@reginpv what is your config in next.config.js?
For me setting trailingSlash to false made that work.

@reginpv
Copy link

reginpv commented Jan 7, 2020

@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

@RobertoPrevato
Copy link

RobertoPrevato commented May 13, 2020

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.

@otospector
Copy link

why this issue closed? anyone have a good advice for handle trailing slash

@Timer
Copy link
Member

Timer commented Jun 10, 2020

See #5214

@balazsorban44
Copy link
Member

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.

@vercel vercel locked as resolved and limited conversation to collaborators Jan 30, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests