diff --git a/src/components/link.js b/src/components/link.js index 9c2a25784..3eaa5a33e 100644 --- a/src/components/link.js +++ b/src/components/link.js @@ -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 diff --git a/src/util/route.js b/src/util/route.js index 9d8e31cd1..730b49db3 100644 --- a/src/util/route.js +++ b/src/util/route.js @@ -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) ) diff --git a/test/unit/specs/route.spec.js b/test/unit/specs/route.spec.js index c9483ab7d..6b78e4106 100644 --- a/test/unit/specs/route.spec.js +++ b/test/unit/specs/route.spec.js @@ -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) + }) }) })