feat: 添加首页的导航守卫

This commit is contained in:
2025-03-06 19:55:08 +08:00
parent c96b07c6eb
commit c70a3de1ca
3 changed files with 278 additions and 81 deletions

View File

@@ -1,5 +1,6 @@
import Vue from 'vue'
import Router from 'vue-router'
import {currentRole} from "@/api/system/role";
Vue.use(Router)
@@ -70,8 +71,26 @@ export const constantRoutes = [
path: 'index',
component: () => import('@/views/index'),
name: 'Index',
meta: { title: '工作台', icon: 'dashboard', affix: true }
meta: { title: '工作台', icon: 'dashboard', affix: true },
beforeEnter: (to, from, next) => {
// 从本地存储获取角色信息
currentRole().then(res => {
const role = res.data.roleKey;
// console.log(role, '当前用户的权限为');
if (role === 'temp') {
next('/temp') // 重定向到临时页面
} else {
next()
}
})
}
},
{
path: 'temp',
component: () => import('@/views/temp'),
name: 'Temp',
meta: { title: '临时页面', icon: 'dashboard', affix: true }
}
]
},
{
@@ -330,9 +349,11 @@ Router.prototype.replace = function push(location) {
return routerReplace.call(this, location).catch(err => err)
}
export default new Router({
const router = new Router({
base: process.env.VUE_APP_CONTEXT_PATH,
mode: 'history', // 去掉url中的#
scrollBehavior: () => ({ y: 0 }),
routes: constantRoutes
})
export default router