Skip to content

Commit bceff56

Browse files
committed
fix: πŸ› treat isActive to case-insensitive
βœ… Closes: #3656
1 parent 084e778 commit bceff56

File tree

3 files changed

+19
-6
lines changed

3 files changed

+19
-6
lines changed

β€Žsrc/components/link.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,11 @@ export default {
7272
? createRoute(null, normalizeLocation(route.redirectedFrom), null, router)
7373
: route
7474

75+
const ignoreCase = current.matched[0].regex.ignoreCase
7576
classes[exactActiveClass] = isSameRoute(current, compareTarget, this.exactPath)
7677
classes[activeClass] = this.exact || this.exactPath
7778
? classes[exactActiveClass]
78-
: isIncludedRoute(current, compareTarget)
79+
: isIncludedRoute(current, compareTarget, ignoreCase)
7980

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

β€Žsrc/util/route.js

+9-5
Original file line numberDiff line numberDiff line change
@@ -116,11 +116,15 @@ function isObjectEqual (a = {}, b = {}): boolean {
116116
})
117117
}
118118

119-
export function isIncludedRoute (current: Route, target: Route): boolean {
120-
return (
121-
current.path.replace(trailingSlashRE, '/').indexOf(
122-
target.path.replace(trailingSlashRE, '/')
123-
) === 0 &&
119+
export function isIncludedRoute (current: Route, target: Route, ignoreCase: boolean = false): boolean {
120+
let currentPath = current.path.replace(trailingSlashRE, '/')
121+
let targetPath = target.path.replace(trailingSlashRE, '/')
122+
if (ignoreCase) {
123+
currentPath = currentPath.toLowerCase()
124+
targetPath = targetPath.toLowerCase()
125+
}
126+
const index = currentPath.indexOf(targetPath)
127+
return (index === 0 &&
124128
(!target.hash || current.hash === target.hash) &&
125129
queryIncludes(current.query, target.query)
126130
)

β€Žtest/unit/specs/route.spec.js

+8
Original file line numberDiff line numberDiff line change
@@ -149,5 +149,13 @@ describe('Route utils', () => {
149149
expect(isIncludedRoute(d, e)).toBe(true)
150150
expect(isIncludedRoute(d, f)).toBe(false)
151151
})
152+
153+
it('ignore case', () => {
154+
const a = { path: '/about' }
155+
const b = { path: '/ABOUT' }
156+
expect(isIncludedRoute(a, b)).toBe(false)
157+
expect(isIncludedRoute(a, b, false)).toBe(false)
158+
expect(isIncludedRoute(a, b, true)).toBe(true)
159+
})
152160
})
153161
})

0 commit comments

Comments
Β (0)