vue automatically obtain login information

// routing interceptor 
router.beforeEach ((to, from, the Next) => {
     if (to.matched.length! = 0 ) {
         if (to.meta.requireAuth) { // determine whether the route need to sign permission 
            if (Boolean (localStorage.getItem ( "the userInfo"))) { // by acquiring the current user vuex state whether there is 
                Next (); 
            } the else { 
                Next ({ 
                    path: '/ Login' , 
                    Query: {the redirect: to.fullPath } // will jump routing path as a parameter, the login is successful jump to the routing 
                }) 
            } 
        } the else{
             IF (Boolean (localStorage.getItem ( "userInfo"))) { // determine whether the login 
                IF (to.path! = "/" && to.path! = "/ The Login") { // determine whether to skip login screen 
                    Next (); 
                } the else {
                     / * * 
                     * anti-refresh, if the login, the login page to jump to change the route, the route is modified after login Home 
                     * / 
                    Next ({ 
                        path: '/ Goods / Goods' 
                    }) 
                } 
            } the else { 
                Next (); 
            } 
        } 
    } the else{ 
        Next ({ 
            path: '/ Login' , 
            Query: {the redirect: to.fullPath} // jump routing path as a parameter, the login is successful jump to the routing 
        }) 
    } 
})

 

Guess you like

Origin www.cnblogs.com/sspeng/p/9994728.html