vue 3.0 project to build a mobile terminal (c) global routing knockdown vue-router beforeEach

The most original route without any interference intercept          other information   

import Vue from 'vue';
import Router from 'vue-router';
import home from './home';

Vue.use(Router);

const RouterModel = new Router({
    routes: [...home]
});
// router.beforeEach
RouterModel.beforeEach((to, from, next) => {
  next();
});



export default RouterModel;

 Conditional routing decisions

router.beforeEach ( function (to, from, the Next) {
   // console.log (to, from, the Next) 
  // needs to log to determine 
  IF (to.meta.auth) {
       / * not empty * / 
      IF (sessionStorage. the getItem ( 'User' )) { 
          Next (); 
      } the else { 
          Next ( '? / Login the redirect =' + to.fullPath)
           // here corresponding to the above, may be written as where 
        / * ** Next ({ 
             path: '/ Login', 
              Query: {the redirect: to.fullPath} 
          }) ** * / 
          // The above writing to another 
      } 
  } 
  the else {
      next();
  }
})

 

Guess you like

Origin www.cnblogs.com/dianzan/p/12371712.html