Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions src/create-route-map.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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}`)
Expand Down
18 changes: 18 additions & 0 deletions test/unit/specs/create-map.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'])
})
})
})