router全局守衛

 1 import Vue from 'vue'//引入vue
 2 import VueRouter from 'vue-router'//引入router
 3 Vue.use(VueRouter)//使用router
 4 const router = new VueRouter({
 5    routes :[
 6        {path:,name:,componenet:} //配置路由規則    
 7 ] ,
 8 mode:'history'//去掉導航欄的#
 9 })
10 
11 //設置全局導航路由
12 router.beforeEach((to,from,next)=>{
13     //to.path,判斷要去往的路由,
14    //若是是登陸和註冊就放行next()
15    if(to.path==='/login'||to.path==='/register'){
16      next() //不帶參數表示放行
17 } else{
18     //判斷是否登陸
19     //store.gettes.isLogin===false
20     next('/login') //跳轉到login ,帶參數表示指定路由
21 }    
22 })

簡單的路由全局守衛vue

相關文章
相關標籤/搜索