Import Vue from 'Vue' import VueRouter from 'vue-router' import nprogress from 'nprogress' // Save to localStorage import { getLocal } from '.. Import store from '@/store/index' import {routerLists} from './routerForList' import {routerLists} from './routerForList' Import {hasRouterList} from './hasRouterList' import {routerListFun, RouterListStr} from './Juridiction' // main panel import Home from '@/views/ Home 'vue. use(VueRouter) // Sort privilege routing array function b(c, d) { return c - d; } // Let routerAlls = [{path: '/home', Component: Home}] const originalPush = VueRouter. Prototype. push; VueRouter.prototype.push = function push(location) { return originalPush.call(this, location).catch(err => err) }; Const createRouter = () => new VueRouter({routes: hasRouterList}) const router = createRouter(); Function resetRouter(params) {const newRouter = createRouter() // Remove router newRouter.matcher; router.addRoutes(params); } / / -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- / / reload a prevent refresh variable blank page / / obtain the data returned from the background to let menuList = store. State. RouterData. MenuList; let arr = []; If (typeof menuList == 'string') {menuList = menulist.replace ('[', '); // Convert string to array if (typeof menuList == 'string') {menuList = menulist.replace ('[', '); menuList = menuList.replace(']', ''); arr = menuList.split(','); } // Let dataNum = [] arr.foreach (item => {datanum.push (+item); }) // sort datanum.sort (b); // reassign to menuList array menuList = dataNum; // Let routerListString = json.stringify (routerLists); let src = routerListStr(routerListString); // Store the object string in the public component store.mit ('routerData/serRouterList', SRC); Let arrList = menuList; RouterAlls [0]. Children = routerListFun(arrList, routerLists); Let mentParse = json.parse (json.stringify (SRC)); let menuListData = routerListFun(arrList, mentParse); store.commit('routerData/setMents', menuListData); ResetRouter (routerAlls); / / -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- - / / determine whether landing, front navigation router. BeforeEach ((the to, from, If (to.meta. Title) {document.title = 'to.meta' + to.meta. Title} if (to.meta (to the path = = "/ login" | | to. The path = = "/ forget" | | to. The path = = '/ private') {/ / if go to the login page directly window.localStorage.removeItem("userInfo"); window.localStorage.removeItem('detailUser'); window.localStorage.removeItem('mentList'); window.localStorage.removeItem('menuList'); window.localStorage.removeItem('numData'); next(); } else {let STR = getLocal('userInfo'); If (STR) {/ / login successfully Continue to call permissions list / / -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- / / obtain the data returned from the background to let menuList = store. State. RouterData. MenuList; let arr = []; If (typeof menuList == 'string') {menuList = menulist.replace ('[', '); // Convert string to array if (typeof menuList == 'string') {menuList = menulist.replace ('[', '); menuList = menuList.replace(']', ''); arr = menuList.split(','); } // Let dataNum = [] arr.foreach (item => {datanum.push (+item); }) // sort datanum.sort (b); // reassign to menuList array menuList = dataNum; // Let routerListString = json.stringify (routerLists); let src = routerListStr(routerListString); // Store the object string in the public component store.mit ('routerData/serRouterList', SRC); Let arrList = menuList; RouterAlls [0]. Children = routerListFun(arrList, routerLists); Let mentParse = json.parse (json.stringify (SRC)); let menuListData = routerListFun(arrList, mentParse); store.commit('routerData/setMents', menuListData); / / store the list of all Windows. LocalStorage. SetItem (' routerAlls, JSON stringify (routerAlls)); ResetRouter (routerAlls); / / -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- / / release routing next (); } else {vue.prototype.$message.warning(' Please login first! '); // router.push('/login'); // Next ('/login'); AfterEach ((to) => {setTimeout(() => {nprogress.done(); }, 200); Let arr = to.path.split('/'); let arr = to.path.split('/'); Arr.shift (); If (arr.length === 3) {arr.pop(); } let s = '/' + arr.join('/'); if (to.path == '/order/lookorder' || to.path == '/order/ordersend') { s = '/order/orderlist' } if (to.path == '/home/startpage') { s = "/home"; } if (to) store.commit('user/changeActive', s) }) export { router }Copy the code