Skip to content

Commit

Permalink
adding guard for startsWith in mixin
Browse files Browse the repository at this point in the history
  • Loading branch information
stephiescastle committed Aug 28, 2024
1 parent 50af4e8 commit e7edb46
Showing 1 changed file with 14 additions and 12 deletions.
26 changes: 14 additions & 12 deletions packages/vue/src/utils/mixins.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,19 +148,21 @@ export const mixinHighlightPrimary = (value: boolean) => {
Useful for dropdown toggles.
*/
export const mixinIsActivePath = (itemPath: string): Boolean => {
const route = useRoute()
const currentPath = route ? route.path : false
const path = itemPath.startsWith('http') ? itemPath.replace(/^.*\/\/[^/]+/, '') : itemPath
const ancestorPath = path ? (path.endsWith('/') ? path : path + '/') : false
if (itemPath) {
const route = useRoute()
const currentPath = route ? route.path : false
const path = itemPath.startsWith('http') ? itemPath.replace(/^.*\/\/[^/]+/, '') : itemPath
const ancestorPath = path ? (path.endsWith('/') ? path : path + '/') : false

if (currentPath && path && ancestorPath) {
if (currentPath === path) {
return true
} else if (currentPath.startsWith('/edu/events')) {
// special treatment since EDU combines News & Events in the main nav
return path.startsWith('/edu/news')
} else {
return currentPath.startsWith(ancestorPath)
if (currentPath && path && ancestorPath) {
if (currentPath === path) {
return true
} else if (currentPath.startsWith('/edu/events')) {
// special treatment since EDU combines News & Events in the main nav
return path.startsWith('/edu/news')
} else {
return currentPath.startsWith(ancestorPath)
}
}
}
return false
Expand Down

0 comments on commit e7edb46

Please sign in to comment.