nuxt
nuxt copied to clipboard
sortRoutes doesn't handle * path correctly
Versions
- nuxt: v2.15.8
- node: 14
Reproduction
Non-simplified reproduction is in the issue reported in @nuxtjs/i18n
- https://github.com/nuxt-community/i18n-module/issues/1480
It boils down to sortRoutes
utility function not sorting the *
correctly. It's not placed at the end thus it catches requests that are meant for later routes in the order.
It works correctly with /*
path.
Nice to talk to you. I am a developer in China, I like the framework of NUXT very much, But it also brings me some troubles Because we do not know much about the bottom implementation and operating principle of NUXT. About the following four issues, I hope to get a little inspiration from you thank you very much
I use NUXT2
Will using Vuex reduce performance? Will Vuex run on the server? and will vuex data be downloaded from the server to the client? Does the use of Vuex increase the memory? The same state, what is the difference between storing in vuex and storing in components
Please don't spam reports with unrelated issues.
We'd like to work on this issue 🙋♂️
Just to be clear about the expected outcome: every route without a *
will be grouped first, any route including a :
will be grouped second, any route including a *
will be grouped third, finally the exact *
match will be sorted as the last route.
I'm not sure about the algorithm or if the rules are that straight-forward. The placement of :
or *
can also affect the sorting probably.
The author of Vue-router made this testing playground for routes ranking that the next version of Vue-router should also be using (not sure if it's up to date with the actual implementation though): https://paths.esm.dev/
The Path Ranker seems to have different output than what's happening in Nuxt right now
It might because it's a VueRouter 4 ranking algorithm that might differ from VueRouter 3 used by Nuxt 2 or the custom Nuxt sorting algorithm.
Also note that VueRouter 4 dropped support for *
(see https://router.vuejs.org/guide/migration/#removed-star-or-catch-all-routes) and had some other breaking changes in handling of route parameters so you can't directly compare those or just bring VueRouter 4's algorithm into Nuxt 2. But the tester could be useful for quickly sanity checking routes that are supported by both.
@joranquinten This issue is for Nuxt 2. In Nuxt 3 we do not sort routes; the router does that for us so the path ranker there should be up-to-date. If you're encountering any issue, perhaps we could discuss in a new issue?
And I would love any PR you might want to put in 😊
We were seeing if we could use the checker to validate some of our assumptions. We're now just using the Nuxt 2 application to validate :)