ant design vue 保留登录页,取消动态路由

 

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开始替换

posted @ 2020-07-10 08:50  周紫妍  Views(1258)  Comments(0Edit  收藏  举报