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
trailing slash in link for legit page works for client side navigation but leads to not found bundle and 404 on hard refresh (ssr) #5214
Comments
Looking forward to this being finally resolved! @timneutkens What's the status of trailing slash issues for Next 7? |
@NathanielHill I could reproduce it on next@7 |
I'm using nextjs 7 and trailing slash is producing a 404 for me on both dev and prod:
And affects:
Simply removing the trailing slash fixes the issue. Trailing slashes are often added by browsers, servers and/or other services where links might be pasted so while I can control internal links, it's hard to control what at what links external users might be arriving on |
I'm also seeing this issue in version 7. Not sure if this is relevant but, I'm aliasing one Next.js project to a subfolder of another Now deployment. So our base url is |
I had to search around a bit to find this issue. I use static deployments on Netlify so it's not an issue on prod, but on development (Next 7) the compilation just freezes if there was a trailing slash, and it was hard to figure out why. I don't think this (not handling trailing slash on dev environment) is a good DX. |
Im also having this issue and it is really annoying, i hope it is fixed soon. |
If you want trailing slash, you can just do this. |
@aluminick I'm sorry, I just tried this and it doesnt work for me. I still get to traling-slashed page (latest release), which is not found after refresh (current behavior). |
@iamstarkov What's the status of this issue? Any solutions beside the |
@dryleaf status: it is still opened |
A similar issue... redirect when multiple forward slashes are added. Example: https://github.com/zeit/next.js////////////issues/5214 |
GitHub urls are irrelevant |
@iamstarkov Not sure what you mean. But after rereading my original post, it looks like I could have been more clear. The GitHub url is meant to be a simple demonstration of how urls should (preferably) work when an app is built with Next.js. In other words, if a user adds an extra slash, the url should still work. |
Any update for nextjs 9 ? |
I'm new to Next but what is the workaround you folks are using for this issue? |
How long does it take for feature to get from canary to master? |
And how exactly it is resolved? just removing the trailing slash? if i access "www.site.com/help/" i get redirected to: "www.site.com/help" , can we have an option there we opt for leaving ending slash? accessing "www.site.com/help/" or "www.site.com/help" will leave or redirect or add "/" at the end to have: "www.site.com/help/" |
@Valnexus see #13333, it includes an experimental option: module.exports = {
experimental: {
trailingSlash: true
}
}
When it's ready. There are still edge cases in the handling that are being solved. Once those have been fixed it can go to stable. |
I tried the latest next canary (9.4.5-canary.27) but when I create When access |
The reason for a redirect is to make sure search engines don't see duplicate content. What's your exact use-case? |
I don't see why it's a closed issue if it isn't merged to a stable release yet. If I understood correctly it's only fixed in the canary release for now, right? |
Issues are closed when their associated pull request lands, as they're available for immediate use on canary. If you need this feature, please upgrade to the canary channel. |
Sounds good. Thanks, @Timer! |
@Janpot I saw
If it has a problem with search engines, Why Github and Twitter did not fix it? There is no specific use-case, it just my opinion that it should work that way. |
@armspkt It is not a problem since there are several ways to solve it. For example Twitter uses So redirect is a viable way to make SEO on your website. You can read more info here. |
@ziserman If we have several way to solve it, we should keep the same url without redirect for user experience. Nuxtjs have several options to choose (undefined, true, false) Should Nextjs have serveral options to choose too? |
@Janpot Our API has trailing slashes in a lot of places. The Latest release raises a lot of 404's on the backend since the Urls with trailing slashes (/api/test/ -> /api/test) do not match |
This comment has been minimized.
This comment has been minimized.
@mlbonniec I've minimized your comment because it causes severe performance regressions in a Next.js app. The latest |
No problem! |
If the latest Next.js canary doesn't fix the bug for you, please open a new issue so we can take a look. 🙏 |
Quick question, how will projects with |
Projects that use |
@Timer once this reaches a full release, would we still need to use the experimental option? |
No, would just be available as-is. |
I guess the |
As far as I'm aware github pages does not have a redirects feature. This does work out of the box on vercel.com though which is also free for hobby projects (like github pages is). |
Hi @Timer Can you explain more? How can I config manually? So here is my situation. On my website, I use |
I'm in the same boat today. I'm using
I still can't find a solution for this one. |
@SamSverko - Did you find a solution? |
@ACPK I have not. I sort of gave up using GitHub pages for this. |
@SamSverko @ACPK It's frustrating as other static site generators such as Hugo do this out of the box. |
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. |
trailing slash in link for legit page works for client side navigation but leads to not found bundle and 404 on hard refresh (ssr)
Bug report
Describe the bug
let me know if title needs further clarification.
all relevant issues has been closed with reasoning that its been fixed in 6-canary (I believe it is not) or by improved serve (which is true only in perhaps production static export).
I'm rewriting my existing blog to next.js and i previously used trailing slashes. Latest
serve
can help with it once i build my next.js powered blog. But in order to fix dev env i need either to get rid of trailing slashes and utilize301 Moved Permanently
in prod; or live with broken trailing slash support in dev.To Reproduce
Here is minimal reproducible case (link to repro repo is below snippet):
Minimal reproducible repo https://github.com/iamstarkov/next.js-trailing-slash-bug-demo
git clone https://github.com/iamstarkov/next.js-trailing-slash-bug-demo
cd next.js-trailing-slash-bug-demo
yarn
yarn dev
http://localhost:3000/_next/static/development/pages/about.js
being 200edhttp://localhost:3000/_next/on-demand-entries-ping?page=/about/
being 200edhttp://localhost:3000/about/
being 404edhttp://localhost:3000/about/
Client pings, but there's no entry for page: /about/
Expected behavior
/about/
shouldnt be resolved as404 not found
/about/
should be resolved as200 ok
Client pings, but there's no entry for page: /about/
/about
and/about/
should work the same wayScreenshots
N/A
System information
Additional context
Add any other context about the problem here.
If you change this code in https://github.com/zeit/next.js/blob/459c1c13d054b37442126889077b7056269eeb35/server/on-demand-entry-handler.js#L242-L249
or
node_modules/next/dist/server/on-demand-entry-handler.js
locallyand restart
next dev
and open http://localhost:3000/ and click about link then:/about
/about/
:I think the problem (at least part of it) is in inability of onDemandEntryHandler's middleware to find page in entries if page has trailing slash.
I hope my 2 hours of investigation and preparation can help with fixing this issue.
The text was updated successfully, but these errors were encountered: