guard against same-route links
This commit is contained in:
parent
7944f6c5fd
commit
c05143cf2c
3 changed files with 57 additions and 2 deletions
|
@ -31,7 +31,9 @@ export class LinkEmbed extends HTMLElement {
|
|||
if (_link.dataset?.href?.startsWith('/') && !!window.router) {
|
||||
e.preventDefault()
|
||||
const route = window.router.resolve({ path: _link.dataset.href })
|
||||
window.router.push(route)
|
||||
if (route.path !== window.router.currentRoute.value.path) {
|
||||
window.router.push(route)
|
||||
}
|
||||
}
|
||||
})
|
||||
this._observers.href = {
|
||||
|
@ -40,6 +42,12 @@ export class LinkEmbed extends HTMLElement {
|
|||
const { element } = this._observers.href
|
||||
element!.setAttribute('href', newVal)
|
||||
element!.dataset.href = newVal
|
||||
if (!!window.router) {
|
||||
const route = window.router.resolve({ path: newVal })
|
||||
if (route.path === window.router.currentRoute.value.path) {
|
||||
element!.classList.add('current-route')
|
||||
}
|
||||
}
|
||||
},
|
||||
}
|
||||
this._observers.target = {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue