From 2d27a4d2dc2f0684f36481069dcc1a61db7bab54 Mon Sep 17 00:00:00 2001 From: Yuki Terashima Date: Tue, 8 Oct 2019 17:48:52 +0900 Subject: [PATCH] fix(utils): error when `router.trailingSlash` is `false` (#6515) --- packages/utils/src/route.js | 2 +- .../test/__snapshots__/route.test.js.snap | 19 ++++++++++--------- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/packages/utils/src/route.js b/packages/utils/src/route.js index fde30efe64..5e82e6fb71 100644 --- a/packages/utils/src/route.js +++ b/packages/utils/src/route.js @@ -176,7 +176,7 @@ export const createRoutes = function createRoutes ({ }) if (trailingSlash !== undefined) { route.pathToRegexpOptions = { ...route.pathToRegexpOptions, strict: true } - route.path = route.path.replace(/\/+$/, '') + (trailingSlash ? '/' : '') + route.path = route.path.replace(/\/+$/, '') + (trailingSlash ? '/' : '') || '/' } parent.push(route) diff --git a/packages/utils/test/__snapshots__/route.test.js.snap b/packages/utils/test/__snapshots__/route.test.js.snap index f65199dd84..1285e2b64d 100644 --- a/packages/utils/test/__snapshots__/route.test.js.snap +++ b/packages/utils/test/__snapshots__/route.test.js.snap @@ -210,15 +210,6 @@ Array [ exports[`util: route util: route create createRoutes should remove trailing slashes when configured to 1`] = ` Array [ - Object { - "chunkName": "pages/index", - "component": "/some/nuxt/app/pages/index.vue", - "name": "index", - "path": "", - "pathToRegexpOptions": Object { - "strict": true, - }, - }, Object { "chunkName": "pages/parent/index", "component": "/some/nuxt/app/pages/parent/index.vue", @@ -269,6 +260,7 @@ Array [ ], "chunkName": "pages/another_route/_id", "component": "/some/nuxt/app/pages/another_route/_id.vue", + "name": "another_route-id", "path": "/another_route/:id?", "pathToRegexpOptions": Object { "strict": true, @@ -283,6 +275,15 @@ Array [ "strict": true, }, }, + Object { + "chunkName": "pages/index", + "component": "/some/nuxt/app/pages/index.vue", + "name": "index", + "path": "/", + "pathToRegexpOptions": Object { + "strict": true, + }, + }, Object { "chunkName": "pages/_param", "component": "/some/nuxt/app/pages/_param.vue",