Skip to content

Commit 5c2a291

Browse files
posvayyx990803
authored andcommitted
Do not remove trailing slash in strict mode (#1557)
1 parent 27d6e59 commit 5c2a291

File tree

2 files changed

+25
-3
lines changed

2 files changed

+25
-3
lines changed

Diff for: src/create-route-map.js

+7-3
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,12 @@ function addRouteRecord (
5757
)
5858
}
5959

60-
const normalizedPath = normalizePath(path, parent)
6160
const pathToRegexpOptions: PathToRegexpOptions = route.pathToRegexpOptions || {}
61+
const normalizedPath = normalizePath(
62+
path,
63+
parent,
64+
pathToRegexpOptions.strict
65+
)
6266

6367
if (typeof route.caseSensitive === 'boolean') {
6468
pathToRegexpOptions.sensitive = route.caseSensitive
@@ -157,8 +161,8 @@ function compileRouteRegex (path: string, pathToRegexpOptions: PathToRegexpOptio
157161
return regex
158162
}
159163

160-
function normalizePath (path: string, parent?: RouteRecord): string {
161-
path = path.replace(/\/$/, '')
164+
function normalizePath (path: string, parent?: RouteRecord, strict?: boolean): string {
165+
if (!strict) path = path.replace(/\/$/, '')
162166
if (path[0] === '/') return path
163167
if (parent == null) return path
164168
return cleanPath(`${parent.path}/${path}`)

Diff for: test/unit/specs/create-map.spec.js

+18
Original file line numberDiff line numberDiff line change
@@ -145,5 +145,23 @@ describe('Creating Route Map', function () {
145145

146146
expect(nameMap.foo.regex.ignoreCase).toBe(false)
147147
})
148+
149+
it('keeps trailing slashes with strict mode', function () {
150+
const { pathList } = createRouteMap([
151+
{
152+
path: '/foo/',
153+
component: Foo,
154+
pathToRegexpOptions: {
155+
strict: true
156+
}
157+
},
158+
{
159+
path: '/bar/',
160+
component: Foo
161+
}
162+
])
163+
164+
expect(pathList).toEqual(['/foo/', '/bar'])
165+
})
148166
})
149167
})

0 commit comments

Comments
 (0)