-
Notifications
You must be signed in to change notification settings - Fork 462
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
Dynamic routes can hijack more specific routes #152
Comments
More mature implementations like ui-router for angular sort the rules by specificity. It's quite complex algorithm though and I'm not sure exactly about specifics. You could argue that it could be job for vue-router itself but if vue router expects users to add routes manually, I guess it won't take responsibility for sorting them. nuxt-i18n generates routes automatically so it probably should handle that. |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Is case-insensitivity a must for the locale part of routes? If not, you could use similar routes as we do in nuxtpress: https://github.com/nuxt/press/blob/develop/packages/core/src/blueprint/index.js#L435-L440 But those routes are case sensitive due to an issue in path-to-regexp. That issue has been fixed but only in the v3 branch and vue-route and nuxt still use v1 due to breaking changes. I've submitted a pr to backport the fix to the v1 branch but that hasnt been accepted yet: pillarjs/path-to-regexp#195 |
Do you mean to use route param (like I was thinking to fix that by just using routes sorting function that you've provided in Nuxt utils. |
I am not fully sure how nuxt-i18n validation works in all cases, but if you create a list of supported locales for a route and apply them like we do in nuxtpress there is no validation needed anymore. --edit-- |
Actually that would require quite some refactoring as now code relies on separate routes for each locale so that those can be matched by name. I think I will try fixing it by sorting routes by specificity. |
With there being a catch-all route (_.vue) in pages directory, depending on the order of locales in configuration, default locale's route could shadow locale-specific one due to being first on the list of generated routes. For example, routes were generated like so: ``` routes: [{ path: "/*", component: _0bdbeb02, name: "all___en" }, { path: "/fr/*", component: _0bdbeb02, name: "all___fr" }], ``` which meant that `/*` route never allowed later ones to be matched. Fix by sorting routes by specificity, using function exposed by `@nuxt/utils` (only from 2.10.2). Resolves #152
Version
v5.3.0
Reproduction link
https://codesandbox.io/s/ly9pnqvp79
Steps to reproduce
/us
to the URLWhat is expected ?
Page shows 'US' in big letters
What is actually happening?
Page shows 'FR'
Additional comments?
This error happens with dynamic nuxt routes. Those are named with
_.vue
(or_slug.vue
but I haven't checked those).The bug seems to be in the order in which routes are generated. For example in this case:
routes are generated in the order in which languages are defined in
locales
array. With this setting, generated routes will look like this:As you can see, the 'catch-all' route (default language) was placed before more specific 'us' route. With this setup, 'us' route is inacessible due to routes being matched by iterating routes in the order they are defined.
Problem can be fixed by generating routes in proper order.
The text was updated successfully, but these errors were encountered: