diff --git a/src/create-route-map.js b/src/create-route-map.js index 6e48e683f..4077392a1 100644 --- a/src/create-route-map.js +++ b/src/create-route-map.js @@ -57,8 +57,12 @@ function addRouteRecord ( ) } - const normalizedPath = normalizePath(path, parent) const pathToRegexpOptions: PathToRegexpOptions = route.pathToRegexpOptions || {} + const normalizedPath = normalizePath( + path, + parent, + pathToRegexpOptions.strict + ) if (typeof route.caseSensitive === 'boolean') { pathToRegexpOptions.sensitive = route.caseSensitive @@ -157,8 +161,8 @@ function compileRouteRegex (path: string, pathToRegexpOptions: PathToRegexpOptio return regex } -function normalizePath (path: string, parent?: RouteRecord): string { - path = path.replace(/\/$/, '') +function normalizePath (path: string, parent?: RouteRecord, strict?: boolean): string { + if (!strict) path = path.replace(/\/$/, '') if (path[0] === '/') return path if (parent == null) return path return cleanPath(`${parent.path}/${path}`) diff --git a/test/unit/specs/create-map.spec.js b/test/unit/specs/create-map.spec.js index 8e0c42ada..9d8e62f36 100644 --- a/test/unit/specs/create-map.spec.js +++ b/test/unit/specs/create-map.spec.js @@ -145,5 +145,23 @@ describe('Creating Route Map', function () { expect(nameMap.foo.regex.ignoreCase).toBe(false) }) + + it('keeps trailing slashes with strict mode', function () { + const { pathList } = createRouteMap([ + { + path: '/foo/', + component: Foo, + pathToRegexpOptions: { + strict: true + } + }, + { + path: '/bar/', + component: Foo + } + ]) + + expect(pathList).toEqual(['/foo/', '/bar']) + }) }) })