Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: 🐛 treat isActive to case-insensitive #3657

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/components/link.js
Expand Up @@ -72,10 +72,11 @@ export default {
? createRoute(null, normalizeLocation(route.redirectedFrom), null, router)
: route

const ignoreCase = current.matched[0].regex.ignoreCase
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any suggestion on how to safely get ignoreCase properly? @posva

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
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
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)
})
})
})