2
0
mirror of https://github.com/tenrok/vue-meta.git synced 2026-06-11 13:02:25 +03:00
Files
vue-meta/src/shared/nav-guards.js
T
pimlie ee12bfcc90 chore: dist size improvements
chore: configure terser to mangle internal properties

chore: do not use default value assignment in function args
2019-09-17 13:55:29 +02:00

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)
}
})
}