1.让菜单生成不经过动态路由
修改 src/router/index.js
import Vue from 'vue'
import Router from 'vue-router'
import { constantRouterMap, asyncRouterMap } from '@/config/router.config'
Vue.use(Router)
export default new Router({
mode: 'history',
base: process.env.BASE_URL,
scrollBehavior: () => ({ y: 0 }),
routes: constantRouterMap.concat(asyncRouterMap)
})
2.增加src/layouts/BasicLayout.vue
第73行起
import { asyncRouterMap } from '@/config/router.config.js'
3.修改src/layouts/BasicLayout.vue第114行起
created () {
this.menus = asyncRouterMap.find((item) => item.path === '/').children
// this.menus = this.mainMenu.find((item) => item.path === '/').children
this.collapsed = !this.sidebarOpened
},
4.修改src/Permission.js
if (Vue.ls.get(ACCESS_TOKEN)) { //是否存在token
next()
} else {
if (to.path === '/user/login') { // 如果是登录页面路径,就直接next()
next()
} else { // 不然就跳转到登录;
next('/user/login')
}
}
从判断是否存在token开始替换
修改完成保留token,取消动态路由