Skip to content

Commit

Permalink
fix: πŸ› treat isActive to case-insensitive
Browse files Browse the repository at this point in the history
βœ… Closes: vuejs#3656
  • Loading branch information
Kyle-Ye committed Oct 29, 2021
1 parent 084e778 commit bceff56
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 6 deletions.
3 changes: 2 additions & 1 deletion src/components/link.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,11 @@ export default {
? createRoute(null, normalizeLocation(route.redirectedFrom), null, router)
: route

const ignoreCase = current.matched[0].regex.ignoreCase
classes[exactActiveClass] = isSameRoute(current, compareTarget, this.exactPath)
classes[activeClass] = this.exact || this.exactPath
? classes[exactActiveClass]
: isIncludedRoute(current, compareTarget)
: isIncludedRoute(current, compareTarget, ignoreCase)

const ariaCurrentValue = classes[exactActiveClass] ? this.ariaCurrentValue : null

Expand Down
14 changes: 9 additions & 5 deletions src/util/route.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,11 +116,15 @@ function isObjectEqual (a = {}, b = {}): boolean {
})
}

export function isIncludedRoute (current: Route, target: Route): boolean {
return (
current.path.replace(trailingSlashRE, '/').indexOf(
target.path.replace(trailingSlashRE, '/')
) === 0 &&
export function isIncludedRoute (current: Route, target: Route, ignoreCase: boolean = false): boolean {
let currentPath = current.path.replace(trailingSlashRE, '/')
let targetPath = target.path.replace(trailingSlashRE, '/')
if (ignoreCase) {
currentPath = currentPath.toLowerCase()
targetPath = targetPath.toLowerCase()
}
const index = currentPath.indexOf(targetPath)
return (index === 0 &&
(!target.hash || current.hash === target.hash) &&
queryIncludes(current.query, target.query)
)
Expand Down
8 changes: 8 additions & 0 deletions test/unit/specs/route.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,5 +149,13 @@ describe('Route utils', () => {
expect(isIncludedRoute(d, e)).toBe(true)
expect(isIncludedRoute(d, f)).toBe(false)
})

it('ignore case', () => {
const a = { path: '/about' }
const b = { path: '/ABOUT' }
expect(isIncludedRoute(a, b)).toBe(false)
expect(isIncludedRoute(a, b, false)).toBe(false)
expect(isIncludedRoute(a, b, true)).toBe(true)
})
})
})

0 comments on commit bceff56

Please sign in to comment.