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

Add possibility to never have trailing slashes #2945

Closed
fabis94 opened this issue Sep 27, 2019 · 1 comment
Closed

Add possibility to never have trailing slashes #2945

fabis94 opened this issue Sep 27, 2019 · 1 comment
Labels
fixed on 4.x This issue has been already fixed on the v4 but exists in v3

Comments

@fabis94
Copy link

fabis94 commented Sep 27, 2019

What problem does this feature solve?

I'm working with an app that has very specific SEO requirements to never have any trailing slashes for any routes. This is impossible when working with nested routes, specifically 'default child routes' (routes with an empty path: ''), because all child routes will always be appended after the trailing slash of the parent route.

For example, consider that I have a parent route with component HomeBase, and two child components HomeIndex (default child route) and HomeArticle (path: ':aid').

const routes = [
    path: '/home',
    components: {
        default: HomeBase
    },
    children: [
        {
            path: '',
            component: HomeIndex
        },
        {
            path: ':aid',
            component: HomeArticle
        }
    ]
]

I want the routes to work like this:

  • /home -> HomeIndex rendered within HomeBase
  • /home/123 -> HomeArticle rendered within HomeBase

But VueRouter makes the routes look like this:

  • /home/ -> HomeIndex rendered within HomeBase
  • /home/123 -> HomeArticle rendered within HomeBase

Even though I probably could link directly to "/home" using , I want to use named routes, so it matters that VueRoute generates the correct path by itself.

What does the proposed API look like?

I'm not sure, as this could be handled multiple ways. At first I thought about making the base (HomeBase) route a named route and routing to that instead of the default child route, but VueRouter then explicitly doesn't render the children ("Named Route has a default child route. When navigating to this named route, the default child route will not be rendered. Remove the name from this route and use the name of the default child route for named links instead."). One way would be to have this functionality be configurable.

Another way would be to set some sort of param on a child route so that its path is always appended on top of the parent path, without the path separator being added inbetween.

@posva posva added the fixed on 4.x This issue has been already fixed on the v4 but exists in v3 label Aug 3, 2020
@posva
Copy link
Member

posva commented Aug 3, 2020

This behavior can be controlled in v4 (https://github.com/vuejs/vue-router-next#improvements) via the strict option but in v3, empty child routes add a trailing slash by design so I don't think we will be able to add this in v3

@posva posva closed this as not planned Won't fix, can't repro, duplicate, stale Jan 31, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
fixed on 4.x This issue has been already fixed on the v4 but exists in v3
Projects
None yet
Development

No branches or pull requests

2 participants