【已解决】 vue框架下的路由守卫在哪里添加,师傅!
import Vue from 'vue'
import Router from 'vue-router'
import { interopDefault } from './utils'
import scrollBehavior from './router.scrollBehavior.js'
const _64d5e66a = () => interopDefault(import('..\\pages\\home\\index.vue' /* webpackChunkName: "pages_home_index" */))
const _14de268a = () => interopDefault(import('..\\pages\\index.vue' /* webpackChunkName: "pages_index" */))
// TODO: remove in Nuxt 3
const emptyFn = () => {}
const originalPush = Router.prototype.push
Router.prototype.push = function push (location, onComplete = emptyFn, onAbort) {
return originalPush.call(this, location, onComplete, onAbort)
}
Vue.use(Router)
export const routerOptions = {
mode: 'history',
base: decodeURI('/'),
linkActiveClass: 'nuxt-link-active',
linkExactActiveClass: 'nuxt-link-exact-active',
scrollBehavior,
routes: [{
path: "/home",
component: _64d5e66a,
name: "home"
}, {
path: "/",
component: _14de268a,
name: "index"
}],
fallback: false
}
export function createRouter () {
return new Router(routerOptions)
这个是router.js //router.beforeEach添加到哪
https://www.sunofbeach.net/a/1236183610147581952
你可以模仿这个百度统计的继承,你看看它是怎么添加的,一样的道理,只不过它的是afterEach
你在main.js里import进来,你不需要注册吗?不注册怎么有效呢?
你导入不就有router了吗?
router.beforeEach添加到哪,就是当前这个router呀