Vueルーティング:ナビゲーションガード

778 ワード

// 1. router.beforeEach() -  url    ,           ,                
//     next()                ,   next("  ")-                       
let isLogin = false; //      
router.beforeEach((to, from, next) => { 
    // to:            
    // from:           
    // next:         ,     next             router-view 

    //    key  :
    // path:     
    // fullPath:     +?     (     )
    // name:     
    // query/params:          
    
    // 2.               ,      
    if (to.path != "/shopcar") {
        next();
    } else if (to.path == "/shopcar" && isLogin == true) {
        next(); //       ,          
    } else { //           ,        ,         
        next("/login"); //       #/  
    }
})