diff --git a/lib/common/utils.js b/lib/common/utils.js
index 37dcfadef2..7e5f846d08 100644
--- a/lib/common/utils.js
+++ b/lib/common/utils.js
@@ -219,21 +219,26 @@ export function createRoutes (files, srcDir) {
if (!b.path.length || b.path === '/') {
return 1
}
+ let i = 0
let res = 0
- let _a = a.path.split('/')
- let _b = b.path.split('/')
- for (let i = 0; i < _a.length; i++) {
+ let y = 0
+ let z = 0
+ const _a = a.path.split('/')
+ const _b = b.path.split('/')
+ for (i = 0; i < _a.length; i++) {
if (res !== 0) {
break
}
- let y = (_a[i].indexOf('*') > -1) ? 2 : (_a[i].indexOf(':') > -1 ? 1 : 0)
- let z = (_b[i].indexOf('*') > -1) ? 2 : (_b[i].indexOf(':') > -1 ? 1 : 0)
+ y = _a[i] === '*' ? 2 : (_a[i].indexOf(':') > -1 ? 1 : 0)
+ z = _b[i] === '*' ? 2 : (_b[i].indexOf(':') > -1 ? 1 : 0)
res = y - z
+ // If a.length >= b.length
if (i === _b.length - 1 && res === 0) {
- res = 1
+ // change order if * found
+ res = _a[i] === '*' ? -1 : 1
}
}
- return res === 0 ? -1 : res
+ return res === 0 ? (_a[i - 1] === '*' && _b[i] ? 1 : -1) : res
})
})
return cleanChildrenRoutes(routes)
diff --git a/test/dynamic-routes.test.js b/test/dynamic-routes.test.js
index c1c8d461b7..0d5b98737f 100644
--- a/test/dynamic-routes.test.js
+++ b/test/dynamic-routes.test.js
@@ -75,7 +75,13 @@ test('Check .nuxt/router.js', t => {
t.is(routes[12].path, '/:key/:id?')
t.is(routes[12].name, 'key-id')
// pages/_.vue
- t.is(routes[13].path, '/*')
- t.is(routes[13].name, 'all')
+ t.is(routes[13].path, '/*/p/*')
+ t.is(routes[13].name, 'all-p-all')
+ // pages/_/_.vue
+ t.is(routes[14].path, '/*/*')
+ t.is(routes[14].name, 'all-all')
+ // pages/_.vue
+ t.is(routes[15].path, '/*')
+ t.is(routes[15].name, 'all')
})
})
diff --git a/test/fixtures/dynamic-routes/pages/_.vue b/test/fixtures/dynamic-routes/pages/_/_.vue
similarity index 100%
rename from test/fixtures/dynamic-routes/pages/_.vue
rename to test/fixtures/dynamic-routes/pages/_/_.vue
diff --git a/test/fixtures/dynamic-routes/pages/_/index.vue b/test/fixtures/dynamic-routes/pages/_/index.vue
new file mode 100644
index 0000000000..e69de29bb2
diff --git a/test/fixtures/dynamic-routes/pages/_/p/_.vue b/test/fixtures/dynamic-routes/pages/_/p/_.vue
new file mode 100644
index 0000000000..e69de29bb2
diff --git a/test/fixtures/dynamic-routes/pages/_key/_id.vue b/test/fixtures/dynamic-routes/pages/_key/_id.vue
index e69de29bb2..467caf2692 100644
--- a/test/fixtures/dynamic-routes/pages/_key/_id.vue
+++ b/test/fixtures/dynamic-routes/pages/_key/_id.vue
@@ -0,0 +1,3 @@
+
+ pages/_key/_id.vue
+
\ No newline at end of file
diff --git a/test/fixtures/dynamic-routes/pages/_slug.vue b/test/fixtures/dynamic-routes/pages/_slug.vue
index e69de29bb2..289c1300dc 100644
--- a/test/fixtures/dynamic-routes/pages/_slug.vue
+++ b/test/fixtures/dynamic-routes/pages/_slug.vue
@@ -0,0 +1,3 @@
+
+ pages/_slug.vue
+
\ No newline at end of file
diff --git a/test/fixtures/dynamic-routes/pages/test/_.vue b/test/fixtures/dynamic-routes/pages/test/_.vue
index e69de29bb2..41514424fa 100644
--- a/test/fixtures/dynamic-routes/pages/test/_.vue
+++ b/test/fixtures/dynamic-routes/pages/test/_.vue
@@ -0,0 +1,3 @@
+
+ pages/test/_.vue
+
\ No newline at end of file
diff --git a/test/fixtures/dynamic-routes/pages/test/index.vue b/test/fixtures/dynamic-routes/pages/test/index.vue
index e69de29bb2..87e2e6be6d 100644
--- a/test/fixtures/dynamic-routes/pages/test/index.vue
+++ b/test/fixtures/dynamic-routes/pages/test/index.vue
@@ -0,0 +1,3 @@
+
+ pages/test/index.vue
+
\ No newline at end of file