Skip to content

Commit d0238b2

Browse files
committed
fix: Run router.afterEach only client
1 parent cc6f383 commit d0238b2

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

src/index.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
import VueAnnouncer from './vue-announcer.vue'
2-
3-
const draf = (cb) => requestAnimationFrame(() => requestAnimationFrame(cb))
2+
import { draf, defaultOptions } from './utils'
43

54
export default function install (Vue, options = {}, router = null) {
5+
if (install.installed) return
6+
install.installed = true
7+
68
// merge options
79
options = {
8-
politeness: 'polite',
9-
complementRoute: 'has loaded',
10+
...defaultOptions,
1011
...options
1112
}
1213

@@ -56,6 +57,7 @@ export default function install (Vue, options = {}, router = null) {
5657

5758
// draf: Resolves the problem of getting the correct document.title when the meta announcer is not passed
5859
// Tested on Vuepress and Nuxt
60+
if (Vue.prototype.$isServer) return
5961
setTimeout(() => {
6062
draf(() => {
6163
const msg = announcer.message || document.title.trim()

src/utils.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
export const draf = (cb) => requestAnimationFrame(() => requestAnimationFrame(cb))
2+
3+
export const defaultOptions = {
4+
politeness: 'polite',
5+
complementRoute: 'has loaded'
6+
}

0 commit comments

Comments
 (0)