Skip to content

Commit 6496b33

Browse files
committed
fix active class for urls with query (fix #209)
1 parent 362138d commit 6496b33

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

src/directives/link.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,11 @@ export default function (Vue) {
7979
}
8080
path = this.path = router._stringifyPath(path)
8181
this.activeRE = path && !this.exact
82-
? new RegExp('^' + path.replace(/\/$/, '').replace(regexEscapeRE, '\\$&') + '(\\/|$)')
82+
? new RegExp(
83+
'^' +
84+
path.replace(/\/$/, '').replace(regexEscapeRE, '\\$&') +
85+
'(\\/|$)'
86+
)
8387
: null
8488
this.updateClasses(this.vm.$route.path)
8589
let isAbsolute = path.charAt(0) === '/'
@@ -105,6 +109,8 @@ export default function (Vue) {
105109
if (this.prevActiveClass !== activeClass) {
106110
_.removeClass(el, this.prevActiveClass)
107111
}
112+
// remove query string before matching
113+
path = path.replace(/\?.*$/, '')
108114
// add new class
109115
if (this.exact) {
110116
if (

test/unit/specs/core.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,7 @@ describe('Core', function () {
338338
expect(linkA.className).toBe('')
339339
expect(linkB.className).toBe('')
340340
expect(linkC.className).toBe('active')
341-
router.go('/a')
341+
router.go('/a?a=123')
342342
nextTick(function () {
343343
expect(linkA.className).toBe('active')
344344
expect(linkB.className).toBe('')

0 commit comments

Comments
 (0)