Skip to content

Commit 762f75e

Browse files
committed
chore: Handling the link event to keep "exact" from the "vue-router"
1 parent 9987ab7 commit 762f75e

File tree

2 files changed

+10
-19
lines changed

2 files changed

+10
-19
lines changed

.eslintrc.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
module.exports = {
22
root: true,
33
env: {
4-
"cypress/globals": true,
4+
'cypress/globals': true,
55
browser: true,
66
node: true
77
},
@@ -10,9 +10,9 @@ module.exports = {
1010
'plugin:vue/essential'
1111
],
1212
plugins: [
13-
"cypress"
13+
'cypress'
1414
],
1515
// add your custom rules here
1616
rules: {},
1717
globals: {}
18-
}
18+
}

src/VueSkipTo.vue

+7-16
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
<template>
2-
<a class="vue-skip-to" :href="to">
2+
<a
3+
class="vue-skip-to"
4+
:href="to"
5+
@click.prevent="handleFocusElement"
6+
>
37
<slot>{{ text }}</slot>
48
</a>
59
</template>
@@ -19,22 +23,9 @@ export default {
1923
}
2024
},
2125
22-
mounted () {
23-
this.init()
24-
},
25-
26-
beforeDestroy () {
27-
window.removeEventListener('hashchange', this.handleFocusElement, false)
28-
},
29-
3026
methods: {
31-
init () {
32-
window.addEventListener('hashchange', this.handleFocusElement, false)
33-
if (location.hash && location.hash.substring(1)) this.handleFocusElement()
34-
},
35-
36-
handleFocusElement () {
37-
this.focusElement(location.hash.substring(1))
27+
handleFocusElement ({ target }) {
28+
this.focusElement(target.getAttribute('href').substring(1))
3829
},
3930
4031
focusElement (id) {

0 commit comments

Comments
 (0)