Next.js: Allow trailing slashes for folders

Created on 30 Sep 2019  Â·  10Comments  Â·  Source: vercel/next.js

Feature request

Is your feature request related to a problem? Please describe.

I created a account folder in the pages folder. And in this account folder, I added a index.js file.

I would like to reach this page through /account/, but I get a 404 error. It is only reachable through /account.

Describe the solution you'd like

When I create a folder, I would like to be able to reach it with a trailing slash.

Most helpful comment

Just to add – some users regularly remove a part of the URL when navigating e.g. documentation, and some percentage of them leave the trailing slash, e.g.:

  • from /section/subsection/page
  • user removes the final two segments to get a higher-level view: /section/
  • user sees a 404

I think a better default would be for Next.js to always automatically redirect to either with or without the trailing slash.

All 10 comments

I think this is a duplicate of https://github.com/zeit/next.js/issues/5214. Out of curiosity, what is the reason that you MUST link with a trailing slash?

I have not written that I "MUST". I wrote that "I would like to". Please don't change my wording.

Sorry, that's not how I meant it. What I meant is: you could just only link to that page without a trailing slash. Unless something inside your project requirements makes this impossible. If it's impossible I'm interested in what dictates this requirement.

I'm only asking out of interest, not trying to put certain words in your mouth. Apologies if it seemed that way, the caps were only meant as emphasis.

Okay, I see what you mean. No problem!

Yes, I could link to that page without a trailing slash, and I currently do. But the URL would be more meaning full if I could add a trailing slash.

For the user, /account means the account page, but /account/ means the account section of the website, i.e. that they are likely other pages in this section.

Our proxy appends trailing slash to any routes without it.
I agree with @lcswillems: users can enter the URL with the trailing slash, which results in a 404.
I feel it very hacky to remove the slashes manually, could next offer any workarounds?

Just to add – some users regularly remove a part of the URL when navigating e.g. documentation, and some percentage of them leave the trailing slash, e.g.:

  • from /section/subsection/page
  • user removes the final two segments to get a higher-level view: /section/
  • user sees a 404

I think a better default would be for Next.js to always automatically redirect to either with or without the trailing slash.

Update, I posted my workaround here: https://github.com/zeit/next.js/issues/5214#issuecomment-540713272

@Janpot the reason that I must use a trailing slash is because Social Login / OAuth federation providers require a trailing slash in their redirect URLs. One of the final pieces of functionality that I'm adding to the site is federated login and to find that ~ this ~ arbitrary decision is going to prevent that functionality is frustrating. Is there a technical reason for this decision that we could contribute to fixing or is this a stubborn design decision?

Maybe will it be solved with the new RFC on custom routing? (https://github.com/zeit/next.js/issues/9081)

Duplicate of #619

Was this page helpful?
0 / 5 - 0 ratings

Related issues

irrigator picture irrigator  Â·  3Comments

pie6k picture pie6k  Â·  3Comments

formula349 picture formula349  Â·  3Comments

kenji4569 picture kenji4569  Â·  3Comments

YarivGilad picture YarivGilad  Â·  3Comments