Skip to content

Commit

Permalink
fix active class for urls with query (fix #209)
Browse files Browse the repository at this point in the history
  • Loading branch information
yyx990803 committed Nov 16, 2015
1 parent 362138d commit 6496b33
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
8 changes: 7 additions & 1 deletion src/directives/link.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,11 @@ export default function (Vue) {
}
path = this.path = router._stringifyPath(path)
this.activeRE = path && !this.exact
? new RegExp('^' + path.replace(/\/$/, '').replace(regexEscapeRE, '\\$&') + '(\\/|$)')
? new RegExp(
'^' +
path.replace(/\/$/, '').replace(regexEscapeRE, '\\$&') +
'(\\/|$)'
)
: null
this.updateClasses(this.vm.$route.path)
let isAbsolute = path.charAt(0) === '/'
Expand All @@ -105,6 +109,8 @@ export default function (Vue) {
if (this.prevActiveClass !== activeClass) {
_.removeClass(el, this.prevActiveClass)
}
// remove query string before matching
path = path.replace(/\?.*$/, '')
// add new class
if (this.exact) {
if (
Expand Down
2 changes: 1 addition & 1 deletion test/unit/specs/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ describe('Core', function () {
expect(linkA.className).toBe('')
expect(linkB.className).toBe('')
expect(linkC.className).toBe('active')
router.go('/a')
router.go('/a?a=123')
nextTick(function () {
expect(linkA.className).toBe('active')
expect(linkB.className).toBe('')
Expand Down

0 comments on commit 6496b33

Please sign in to comment.