Skip to content

Commit b858cad

Browse files
committed
Fix hash comparison for isSameRoute (#635)
when one of a.hash and b.hash is undefined while the other is empty string This bug causes active class not being applied when using named view + exact matching
1 parent 3c7f007 commit b858cad

File tree

3 files changed

+16
-9
lines changed

3 files changed

+16
-9
lines changed

examples/active-links/app.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ const router = new VueRouter({
2525
{ path: '/about', component: About },
2626
{ path: '/users', component: Users,
2727
children: [
28-
{ path: ':username', component: User }
28+
{ path: ':username', name: 'user', component: User }
2929
]
3030
}
3131
]
@@ -50,6 +50,11 @@ new Vue({
5050
/users/evan?foo=bar
5151
</router-link>
5252
</li>
53+
<li><!-- #635 -->
54+
<router-link :to="{ name: 'user', params: { username: 'evan' }, query: { foo: 'bar' }}" exact>
55+
/users/evan?foo=bar (named view + exact match)
56+
</router-link>
57+
</li>
5358
<li>
5459
<router-link :to="{ path: '/users/evan', query: { foo: 'bar', baz: 'qux' }}">
5560
/users/evan?foo=bar&baz=qux

src/util/route.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@ export function isSameRoute (a: Route, b: ?Route): boolean {
66
} else if (a.path && b.path) {
77
return (
88
a.path === b.path &&
9-
a.hash === b.hash &&
9+
(a.hash || '') === (b.hash || '') &&
1010
isObjectEqual(a.query, b.query)
1111
)
1212
} else if (a.name && b.name) {
1313
return (
1414
a.name === b.name &&
15-
a.hash === b.hash &&
15+
(a.hash || '') === (b.hash || '') &&
1616
isObjectEqual(a.query, b.query) &&
1717
isObjectEqual(a.params, b.params)
1818
)

test/e2e/specs/active-links.js

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ module.exports = {
33
browser
44
.url('http://localhost:8080/active-links/')
55
.waitForElementVisible('#app', 1000)
6-
.assert.count('li a', 10)
6+
.assert.count('li a', 11)
77
// assert correct href with base
88
.assert.attributeContains('li:nth-child(1) a', 'href', '/active-links/')
99
.assert.attributeContains('li:nth-child(2) a', 'href', '/active-links/')
@@ -12,9 +12,10 @@ module.exports = {
1212
.assert.attributeContains('li:nth-child(5) a', 'href', '/active-links/users/evan')
1313
.assert.attributeContains('li:nth-child(6) a', 'href', '/active-links/users/evan#foo')
1414
.assert.attributeContains('li:nth-child(7) a', 'href', '/active-links/users/evan?foo=bar')
15-
.assert.attributeContains('li:nth-child(8) a', 'href', '/active-links/users/evan?baz=qux&foo=bar')
16-
.assert.attributeContains('li:nth-child(9) a', 'href', '/active-links/about')
15+
.assert.attributeContains('li:nth-child(8) a', 'href', '/active-links/users/evan?foo=bar')
16+
.assert.attributeContains('li:nth-child(9) a', 'href', '/active-links/users/evan?baz=qux&foo=bar')
1717
.assert.attributeContains('li:nth-child(10) a', 'href', '/active-links/about')
18+
.assert.attributeContains('li:nth-child(11) a', 'href', '/active-links/about')
1819
.assert.containsText('.view', 'Home')
1920

2021
assertActiveLinks(1, [1, 2])
@@ -23,10 +24,11 @@ module.exports = {
2324
assertActiveLinks(4, [1, 3, 4])
2425
assertActiveLinks(5, [1, 3, 5])
2526
assertActiveLinks(6, [1, 3, 5, 6])
26-
assertActiveLinks(7, [1, 3, 5, 7])
27+
assertActiveLinks(7, [1, 3, 5, 7, 8])
2728
assertActiveLinks(8, [1, 3, 5, 7, 8])
28-
assertActiveLinks(9, [1, 9], [10])
29-
assertActiveLinks(10, [1, 9], [10])
29+
assertActiveLinks(9, [1, 3, 5, 7, 9])
30+
assertActiveLinks(10, [1, 10], [11])
31+
assertActiveLinks(11, [1, 10], [11])
3032

3133
browser.end()
3234

0 commit comments

Comments
 (0)