Skip to content

Commit 1722be2

Browse files
fnlctrlyyx990803
authored andcommitted
Allow trailing slashes in path comparison (fix #628) (#632)
* Allow trailing slashes in path comparison (fix #628) * Modify existing test for isSameRoute
1 parent b700363 commit 1722be2

File tree

2 files changed

+3
-2
lines changed

2 files changed

+3
-2
lines changed

src/util/route.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
/* @flow */
2+
const trailingSlashRE = /\/$/
23

34
export function isSameRoute (a: Route, b: ?Route): boolean {
45
if (!b) {
56
return false
67
} else if (a.path && b.path) {
78
return (
8-
a.path === b.path &&
9+
a.path.replace(trailingSlashRE, '') === b.path.replace(trailingSlashRE, '') &&
910
a.hash === b.hash &&
1011
isObjectEqual(a.query, b.query)
1112
)

test/unit/specs/route.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ describe('Route utils', () => {
99
query: { foo: 'bar', arr: [1, 2] }
1010
}
1111
const b = {
12-
path: '/a',
12+
path: '/a/', // Allow trailing slash
1313
hash: '#hi',
1414
query: { arr: ['1', '2'], foo: 'bar' }
1515
}

0 commit comments

Comments
 (0)