Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
剑九 六千里
vue-vben-admin
提交
87583c8b
V
vue-vben-admin
项目概览
剑九 六千里
/
vue-vben-admin
与 Fork 源项目一致
从无法访问的项目Fork
通知
2
Star
1
Fork
1
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
V
vue-vben-admin
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
87583c8b
编写于
7月 14, 2021
作者:
无
无木
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix: ensure PAGE_NOT_FOUND_ROUTE exist
修复某些情况下404路由可能白屏的问题
上级
1e633790
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
28 addition
and
23 deletion
+28
-23
src/router/guard/permissionGuard.ts
src/router/guard/permissionGuard.ts
+26
-23
src/store/modules/user.ts
src/store/modules/user.ts
+2
-0
未找到文件。
src/router/guard/permissionGuard.ts
浏览文件 @
87583c8b
...
...
@@ -8,7 +8,6 @@ import { useUserStoreWithOut } from '/@/store/modules/user';
import
{
PAGE_NOT_FOUND_ROUTE
}
from
'
/@/router/routes/basic
'
;
import
{
RootRoute
}
from
'
/@/router/routes
'
;
import
{
omit
}
from
'
lodash-es
'
;
const
LOGIN_PATH
=
PageEnum
.
BASE_LOGIN
;
...
...
@@ -19,20 +18,26 @@ const whitePathList: PageEnum[] = [LOGIN_PATH];
export
function
createPermissionGuard
(
router
:
Router
)
{
const
userStore
=
useUserStoreWithOut
();
const
permissionStore
=
usePermissionStoreWithOut
();
router
.
beforeEach
(
async
(
to
,
from
)
=>
{
router
.
beforeEach
(
async
(
to
,
from
,
next
)
=>
{
// Jump to the 404 page after processing the login
if
(
from
.
path
===
LOGIN_PATH
&&
to
.
name
===
PAGE_NOT_FOUND_ROUTE
.
name
)
{
next
(
userStore
.
getUserInfo
.
homePath
||
PageEnum
.
BASE_HOME
);
return
;
}
if
(
from
.
path
===
ROOT_PATH
&&
to
.
path
===
PageEnum
.
BASE_HOME
&&
userStore
.
getUserInfo
.
homePath
&&
userStore
.
getUserInfo
.
homePath
!==
PageEnum
.
BASE_HOME
)
{
//
next(userStore.getUserInfo.homePath);
return
userStore
.
getUserInfo
.
homePath
;
next
(
userStore
.
getUserInfo
.
homePath
);
return
;
}
// Whitelist can be directly entered
if
(
whitePathList
.
includes
(
to
.
path
as
PageEnum
))
{
//
next();
next
();
return
;
}
...
...
@@ -42,7 +47,7 @@ export function createPermissionGuard(router: Router) {
if
(
!
token
)
{
// You can access without permission. You need to set the routing meta.ignoreAuth to true
if
(
to
.
meta
.
ignoreAuth
)
{
//
next();
next
();
return
;
}
...
...
@@ -57,18 +62,12 @@ export function createPermissionGuard(router: Router) {
redirect
:
to
.
path
,
};
}
//next(redirectData);
return
redirectData
;
}
// Jump to the 404 page after processing the login
if
(
from
.
path
===
LOGIN_PATH
&&
to
.
name
===
PAGE_NOT_FOUND_ROUTE
.
name
)
{
//next(userStore.getUserInfo.homePath || PageEnum.BASE_HOME);
return
userStore
.
getUserInfo
.
homePath
||
PageEnum
.
BASE_HOME
;
next
(
redirectData
);
return
;
}
if
(
permissionStore
.
getIsDynamicAddedRoute
)
{
//
next();
next
();
return
;
}
...
...
@@ -78,14 +77,18 @@ export function createPermissionGuard(router: Router) {
router
.
addRoute
(
route
as
unknown
as
RouteRecordRaw
);
});
const
redirectPath
=
(
from
.
query
.
redirect
||
to
.
path
)
as
string
;
const
redirect
=
decodeURIComponent
(
redirectPath
);
const
nextData
=
to
.
path
===
redirect
?
{
...
omit
(
to
,
[
'
name
'
,
'
params
'
]),
replace
:
true
}
:
{
path
:
redirect
};
router
.
addRoute
(
PAGE_NOT_FOUND_ROUTE
as
unknown
as
RouteRecordRaw
);
permissionStore
.
setDynamicAddedRoute
(
true
);
// next(nextData);
return
nextData
;
if
(
to
.
name
===
PAGE_NOT_FOUND_ROUTE
.
name
)
{
// 动态添加路由后,此处应当重定向到fullPath,否则会加载404页面内容
next
({
path
:
to
.
fullPath
,
replace
:
true
});
}
else
{
const
redirectPath
=
(
from
.
query
.
redirect
||
to
.
path
)
as
string
;
const
redirect
=
decodeURIComponent
(
redirectPath
);
const
nextData
=
to
.
path
===
redirect
?
{
...
to
,
replace
:
true
}
:
{
path
:
redirect
};
next
(
nextData
);
}
});
}
src/store/modules/user.ts
浏览文件 @
87583c8b
...
...
@@ -13,6 +13,7 @@ import { useMessage } from '/@/hooks/web/useMessage';
import
{
router
}
from
'
/@/router
'
;
import
{
usePermissionStore
}
from
'
/@/store/modules/permission
'
;
import
{
RouteRecordRaw
}
from
'
vue-router
'
;
import
{
PAGE_NOT_FOUND_ROUTE
}
from
'
/@/router/routes/basic
'
;
interface
UserState
{
userInfo
:
Nullable
<
UserInfo
>
;
...
...
@@ -98,6 +99,7 @@ export const useUserStore = defineStore({
routes
.
forEach
((
route
)
=>
{
router
.
addRoute
(
route
as
unknown
as
RouteRecordRaw
);
});
router
.
addRoute
(
PAGE_NOT_FOUND_ROUTE
as
unknown
as
RouteRecordRaw
);
permissionStore
.
setDynamicAddedRoute
(
true
);
}
await
router
.
replace
(
userInfo
.
homePath
||
PageEnum
.
BASE_HOME
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录