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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Trailing slash option #422

Closed
manniL opened this issue Aug 28, 2019 · 9 comments
Closed

Trailing slash option #422

manniL opened this issue Aug 28, 2019 · 9 comments

Comments

@manniL
Copy link
Member

@manniL manniL commented Aug 28, 2019

Heyo 馃憢

it'd be great to have an option for adding/removing trailing slashes for routes coming from localePath. A global setting would suffice IMO and could be applied around the marked lines.

const { route: { fullPath } } = router.resolve(localizedRoute)
return fullPath

trailingSlashes: true

/abc/ -> /abc/ (keeps the same)
/abc -> /abc/ (changes)

trailingSlashes: false

/abc -> /abc (keeps the same)
/abc/ -> /abc (changes)

trailingSlashes: undefined (default)

/abc/ -> /abc/ (keeps the same)
/abc -> /abc (keeps the same)

@rchl

This comment has been minimized.

Copy link
Collaborator

@rchl rchl commented Aug 28, 2019

Being a slightly old dog that worked on pages before frameworks and SPAs, it strikes me as wrong as routes with and without slash can be different routes in Apache for example (one is a file and other a directory with index file). I guess these days that distinction can be blurry (and for less confusion, maybe should be) so I'm not entirely against an option. That is, as long as with Nuxt (and VueRouter) there is always guarantee that those will be handled the same. I'm a bit concerned that it might not be the case...

@manniL

This comment has been minimized.

Copy link
Member Author

@manniL manniL commented Aug 28, 2019

You are right, "back then" the distinction was exactly that. a folder (+ index) or a file.

Nowadays it doesn't matter a lot and these usually aren't different routes. One variant should be the main one (for SEO purposes, canonical URLs and so on) though.

Also, it'd be a bad experience for the user if /dogs/ puts out sth. different than /dogs.

Vue router handles both kinds equally by default, except if you are enabling strict mode in the vue router "manually", but you'd only do that if you know what you are doing.

@rchl

This comment has been minimized.

Copy link
Collaborator

@rchl rchl commented Aug 28, 2019

OK, then it makes sense.

I do wonder now if it would make more sense for Nuxt to handle that though...

If trailing slashes would be added by Nuxt and it would also add route.pathToRegexpOptions = { strict: true } to all routes, then vue-router would resolve routes with trailing slash preserved.

(I've tested that with some quick hacking and seen it working albeit with some issues when redirecting. But that is probably separate issue in nuxt-i18n.)

@manniL

This comment has been minimized.

Copy link
Member Author

@manniL manniL commented Aug 29, 2019

I've actually thought about the same but this can only be handled after
vuejs/vue-router#2913 has been resolved.

@manniL

This comment has been minimized.

Copy link
Member Author

@manniL manniL commented Aug 29, 2019

There we go nuxt/nuxt.js#6331

@manniL manniL closed this Aug 29, 2019
@dacxjo

This comment has been minimized.

Copy link

@dacxjo dacxjo commented Sep 12, 2019

I was just asking this in https://cmty.app/nuxt/nuxt.js/issues/c9751 a few days ago.

Any workarounds for v2.9.x ?

@manniL

This comment has been minimized.

Copy link
Member Author

@manniL manniL commented Sep 12, 2019

@dacxjo I'd suggest to upgrade to nuxt-edge if you really need that feature right now 鈽猴笍

Ofc you can implement it on your own if you want. You can check what I did in the related PR and mimic that.

@dacxjo

This comment has been minimized.

Copy link

@dacxjo dacxjo commented Sep 12, 2019

Got it, thanks @manniL

@gangsthub

This comment has been minimized.

Copy link
Contributor

@gangsthub gangsthub commented Oct 25, 2019

Thanks, @manniL! Solved since Nuxt v2.10.0 馃憦

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
4 participants
You can鈥檛 perform that action at this time.