fix(router): 按账号菜单落地避免创作者进入 404
This commit is contained in:
1 parent
8535305185
commit
0d862dfe1d
2 files changed
+10
-2
No files matched your search
+8
-1
@@ -25,13 +25,20 @@ router.beforeEach(async (to, from, next) => {
|
||||
const userStore = useUserStoreWithOut()
|
||||
if (userStore.getUserInfo) {
|
||||
if (to.path === '/login') {
|
||||
next({ path: '/' })
|
||||
// 已登录再访问登录页:按当前账号的菜单落地,不能回 '/'(静态路由会 redirect 到 /dashboard/index,
|
||||
// 创作者没有该路由,直接掉 404)
|
||||
next({ path: landingPath(), replace: true })
|
||||
} else {
|
||||
if (permissionStore.getIsAddRouters) {
|
||||
// 已加过路由:只有还是同一个账号才能直接放行。
|
||||
// 换账号时(例如超管退出后创作者登录)必须重建,否则侧边栏/路由会残留上一个账号的
|
||||
const username = userStore.getUserInfo?.username || ''
|
||||
if (permissionStore.getRoutersOwner === username) {
|
||||
// 访问根路径时同样按账号菜单落地,避免走静态 redirect 掉进 /dashboard/index
|
||||
if (to.path === '/') {
|
||||
next({ path: landingPath(), replace: true })
|
||||
return
|
||||
}
|
||||
next()
|
||||
return
|
||||
}
|
||||
|
||||
+2
-1
@@ -8,9 +8,10 @@ import { AppIcons } from '@/constants/icons'
|
||||
|
||||
export const constantRouterMap: AppRouteRecordRaw[] = [
|
||||
{
|
||||
// 不写死 redirect:vue-router 会在守卫之前就把 '/' 解析成 redirect 目标,
|
||||
// 创作者没有 /dashboard/index 路由会直接 404。落地页交给 permission.ts 按账号菜单决定。
|
||||
path: '/',
|
||||
component: Layout,
|
||||
redirect: '/dashboard/index',
|
||||
name: 'Root',
|
||||
meta: {
|
||||
hidden: true
|
||||
|
||||
Reference in new issue
Block a user