From 267373f910f1e7800747fbc18acb2d72749241a7 Mon Sep 17 00:00:00 2001 From: Mohammad Saleh Fadaei Date: Thu, 1 Jul 2021 16:23:49 +0430 Subject: [PATCH 1/2] fix(utils): Router config trailingSlash causes error with dynamic nuxt-child routes --- packages/utils/src/route.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/packages/utils/src/route.js b/packages/utils/src/route.js index edc9616d6794..b52c86a1a262 100644 --- a/packages/utils/src/route.js +++ b/packages/utils/src/route.js @@ -56,7 +56,11 @@ function cleanChildrenRoutes (routes, isChild = false, routeNameSplitter = '-', route.path = isChild ? route.path.replace('/', '') : route.path if (route.path.includes('?')) { if (route.name.endsWith(`${routeNameSplitter}index`)) { - route.path = route.path.replace(/\?$/, '') + if (trailingSlash) { + route.path = route.path.replace(/\?\/$/, '/') + } else { + route.path = route.path.replace(/\?$/, '') + } } const names = route.name.replace(regExpParentRouteName, '').split(routeNameSplitter) const paths = route.path.split('/') From 563c5bcf2704c81f8d1cd5582348ad199b4c9015 Mon Sep 17 00:00:00 2001 From: Mohammad Saleh Fadaei Date: Thu, 1 Jul 2021 17:01:39 +0430 Subject: [PATCH 2/2] refacotor: use safer regex to remove `?` mark --- packages/utils/src/route.js | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/packages/utils/src/route.js b/packages/utils/src/route.js index b52c86a1a262..97d53ae1032d 100644 --- a/packages/utils/src/route.js +++ b/packages/utils/src/route.js @@ -56,11 +56,7 @@ function cleanChildrenRoutes (routes, isChild = false, routeNameSplitter = '-', route.path = isChild ? route.path.replace('/', '') : route.path if (route.path.includes('?')) { if (route.name.endsWith(`${routeNameSplitter}index`)) { - if (trailingSlash) { - route.path = route.path.replace(/\?\/$/, '/') - } else { - route.path = route.path.replace(/\?$/, '') - } + route.path = route.path.replace(/\?\/?$/, trailingSlash ? '/' : '') } const names = route.name.replace(regExpParentRouteName, '').split(routeNameSplitter) const paths = route.path.split('/')