Skip to content

Support for unified trailing slash handling #15462

@TheAlexLichter

Description

@TheAlexLichter

Describe the feature

Yes, here we go again. I'd like to propose uniform trailing slash handling - as I did for Nuxt 2 - again. But I firmly believe that the implementation can be better, less error prone and even easier with Nuxt 3.

Why?

Trailing slash handling is crucial when it comes to SEO. Right now, the content shown for /my-route and /my-route/ is already the same. But ideally, one of these versions should not exist (and instead redirect to the other). If that is not possible, a fitting canonical URL should be set to define the preferred URL.

Now it seems that it is rather easy, we could go and simply use the pages:extend hook and apply/remove the trailing slash and add some nitro page rules (or a middleware) for redirects.

But there is another important part: the internal linking. Often neglected, it is key for a good on-page SEO. Ideally, the implementation of this feature would cover correct internal linking too. Ideally, also working with any module, like the i18n module.

Proposal

  1. Have a global option to enforce a trailling slash /route/ or no slash /route for every internal Nuxt route that exists, ideally including Nitro server-routes (API routes are not that important in this case)
  2. The "disallowed" version should redirect to the correct version
  3. <NuxtLink> should be aware of this choice and adapt linking correctly so the preferred version is the one that will be rendered.

Additional information

  • Would you be willing to help implement this feature?
  • Could this feature be implemented as a module?

Final checks

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions