Skip to content

Commit

Permalink
fix(utils): update route order check to take only * into account and …
Browse files Browse the repository at this point in the history
…change the priority of param route
  • Loading branch information
marcelobotega committed May 16, 2023
1 parent dcbf3b7 commit bce4af8
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 20 deletions.
4 changes: 2 additions & 2 deletions packages/utils/src/route.js
Expand Up @@ -126,8 +126,8 @@ export const sortRoutes = function sortRoutes (routes) {
if (res !== 0) {
break
}
y = _a[i].includes('*') ? 2 : _a[i].includes(':') ? 1 : 0
z = _b[i].includes('*') ? 2 : _b[i].includes(':') ? 1 : 0
y = _a[i] === '*' ? 3 : _a[i].includes(':') ? 2 : _a[i].includes('*') ? 1 : 0
z = _b[i] === '*' ? 3 : _b[i].includes(':') ? 2 : _b[i].includes('*') ? 1 : 0
res = y - z
// If a.length >= b.length
if (i === _b.length - 1 && res === 0) {
Expand Down
34 changes: 17 additions & 17 deletions packages/utils/test/__snapshots__/route.test.js.snap
Expand Up @@ -298,6 +298,19 @@ exports[`util: route util: route sortRoutes sortRoutes should sort routes 1`] =
"name": "index",
"path": "/",
},
{
"children": [
{
"chunkName": "pages/another_route/rout*",
"component": "/some/nuxt/app/pages/another_route/rout*.vue",
"name": "another_route-rout*",
"path": "",
},
],
"chunkName": "pages/another_route/rout*",
"component": "/some/nuxt/app/pages/another_route/rout*.vue",
"path": "/another_route/rout*",
},
{
"chunkName": "pages/another_route/_id",
"component": "/some/nuxt/app/pages/another_route/_id.vue",
Expand All @@ -317,30 +330,17 @@ exports[`util: route util: route sortRoutes sortRoutes should sort routes 1`] =
"path": "/parent/*",
},
{
"children": [
{
"chunkName": "pages/another_route/rout*",
"component": "/some/nuxt/app/pages/another_route/rout*.vue",
"name": "another_route-rout*",
"path": "",
},
],
"chunkName": "pages/another_route/rout*",
"component": "/some/nuxt/app/pages/another_route/rout*.vue",
"path": "/another_route/rout*",
"chunkName": "pages/de*",
"component": "/some/nuxt/app/pages/de*.vue",
"name": "de*",
"path": "/de*",
},
{
"chunkName": "pages/_param",
"component": "/some/nuxt/app/pages/_param.vue",
"name": "param",
"path": "/:param",
},
{
"chunkName": "pages/de*",
"component": "/some/nuxt/app/pages/de*.vue",
"name": "de*",
"path": "/de*",
},
{
"chunkName": "pages/*",
"component": "/some/nuxt/app/pages/*.vue",
Expand Down
2 changes: 1 addition & 1 deletion packages/utils/test/route.test.js
Expand Up @@ -295,8 +295,8 @@ describe('util: route', () => {
{ path: '/de/tech' },
{ path: '/' },
{ path: '/de/:post' },
{ path: '/:post' },
{ path: '/de*' },
{ path: '/:post' },
{ path: '*' }
]
)
Expand Down

0 comments on commit bce4af8

Please sign in to comment.