mirror of
https://github.com/tenrok/vue-meta.git
synced 2026-06-11 13:02:25 +03:00
ee12bfcc90
chore: configure terser to mangle internal properties chore: do not use default value assignment in function args
29 lines
668 B
JavaScript
29 lines
668 B
JavaScript
import { isFunction } from '../utils/is-type'
|
|
import { rootConfigKey } from './constants'
|
|
import { pause, resume } from './pausing'
|
|
|
|
export function addNavGuards (rootVm) {
|
|
const router = rootVm.$router
|
|
|
|
// return when nav guards already added or no router exists
|
|
if (rootVm[rootConfigKey].navGuards || !router) {
|
|
/* istanbul ignore next */
|
|
return
|
|
}
|
|
|
|
rootVm[rootConfigKey].navGuards = true
|
|
|
|
router.beforeEach((to, from, next) => {
|
|
pause(rootVm)
|
|
next()
|
|
})
|
|
|
|
router.afterEach(() => {
|
|
const { metaInfo } = resume(rootVm)
|
|
|
|
if (metaInfo && isFunction(metaInfo.afterNavigation)) {
|
|
metaInfo.afterNavigation(metaInfo)
|
|
}
|
|
})
|
|
}
|