一、前言
某些项目可能并不需要首页,但在若依中想要实现不显示首页,并根据不同角色登录后跳转至该角色的第一个动态路由的页面需要自己实现,若依中没有实现该功能的特定代码。
二、代码
1. src\\permission.js
在 src\\permission.js 中添加下面的代码,可将原有代码注释。
router.beforeEach((to, from, next) => {
NProgress.start()
if (getToken()) {
to.meta.title && useSettingsStore().setTitle(to.meta.title)
/* has token*/
if (to.path === \'/login\') {
next({ path: \'/\' })
NProgress.done()
} else if (whiteList.indexOf(to.path) !== -1) {
next()
} else {
if (useUserStore().roles.length === 0) {
isRelogin.show = true
// 判断当前用户是否已拉取完user_info信息
useUserStore().getInfo().then(() => {
isRelogin.show = false
usePermissionStore().generateRoutes().then(accessRoutes => {
// 根据roles权限生成可访问的路由表
accessRoutes.forEach(route => {
if (!isHttp(route.path)) {
router.addRoute(route) // 动态添加可访问路由表
console.log(route,\"route\")
}
})
console.log(to.fullPath,\"to.fullPath\")
if (to.fullPath == \'/index\') {
console.log(accessRoutes,\"accessRoutes\")
// 当登录之后,直
平台声明:以上文章转载于《CSDN》,文章全部或者部分内容、文字的真实性、完整性、及时性本站不作任何保证或承诺,仅作参考。
版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
原文链接:https://blog.csdn.net/m0_57203243/article/details/142484425