Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
剑九 六千里
vue-vben-admin
提交
237e65ea
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,发现更多精彩内容 >>
提交
237e65ea
编写于
7月 14, 2021
作者:
无
无木
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix: resolving `Vue Router warn`
移除因为动态加载路由而产生的vue-router警告
上级
6350224a
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
56 addition
and
25 deletion
+56
-25
CHANGELOG.zh_CN.md
CHANGELOG.zh_CN.md
+2
-1
src/router/constant.ts
src/router/constant.ts
+2
-0
src/router/guard/permissionGuard.ts
src/router/guard/permissionGuard.ts
+21
-16
src/router/routes/basic.ts
src/router/routes/basic.ts
+9
-3
src/router/routes/index.ts
src/router/routes/index.ts
+7
-1
src/store/modules/user.ts
src/store/modules/user.ts
+15
-4
未找到文件。
CHANGELOG.zh_CN.md
浏览文件 @
237e65ea
...
...
@@ -22,11 +22,12 @@
-
修复悬停触发模式下左侧混合菜单会在没有子菜单且被激活时直接跳转路由
-
**Breadcrumb**
修复带有重定向的菜单点击无法跳转的问题
-
**Markdown**
修复初始化异常以及不能正确地动态设置 value 的问题
-
**Modal**
确保 props 正确被传递
-
**其它**
-
修复菜单默认折叠的配置不起作用的问题
-
修复
`safari`
浏览器报错导致网站打不开
-
修复在 window 上,拉取代码后 eslint 因 endOfLine 而保错问题
-
**Modal**
确保 props 正确被传递
-
修复因动态路由而产生的
`Vue Router warn`
### 🎫 Chores
...
...
src/router/constant.ts
浏览文件 @
237e65ea
...
...
@@ -2,6 +2,8 @@ export const REDIRECT_NAME = 'Redirect';
export
const
PARENT_LAYOUT_NAME
=
'
ParentLayout
'
;
export
const
PAGE_NOT_FOUND_NAME
=
'
PageNotFound
'
;
export
const
EXCEPTION_COMPONENT
=
()
=>
import
(
'
../views/sys/exception/Exception.vue
'
);
/**
...
...
src/router/guard/permissionGuard.ts
浏览文件 @
237e65ea
...
...
@@ -8,6 +8,7 @@ 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
;
...
...
@@ -18,26 +19,20 @@ const whitePathList: PageEnum[] = [LOGIN_PATH];
export
function
createPermissionGuard
(
router
:
Router
)
{
const
userStore
=
useUserStoreWithOut
();
const
permissionStore
=
usePermissionStoreWithOut
();
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
;
}
router
.
beforeEach
(
async
(
to
,
from
)
=>
{
if
(
from
.
path
===
ROOT_PATH
&&
to
.
path
===
PageEnum
.
BASE_HOME
&&
userStore
.
getUserInfo
.
homePath
&&
userStore
.
getUserInfo
.
homePath
!==
PageEnum
.
BASE_HOME
)
{
next
(
userStore
.
getUserInfo
.
homePath
);
return
;
//
next(userStore.getUserInfo.homePath);
return
userStore
.
getUserInfo
.
homePath
;
}
// Whitelist can be directly entered
if
(
whitePathList
.
includes
(
to
.
path
as
PageEnum
))
{
next
();
//
next();
return
;
}
...
...
@@ -47,7 +42,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
;
}
...
...
@@ -62,12 +57,18 @@ export function createPermissionGuard(router: Router) {
redirect
:
to
.
path
,
};
}
next
(
redirectData
);
return
;
//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
;
}
if
(
permissionStore
.
getIsDynamicAddedRoute
)
{
next
();
//
next();
return
;
}
...
...
@@ -79,8 +80,12 @@ export function createPermissionGuard(router: Router) {
const
redirectPath
=
(
from
.
query
.
redirect
||
to
.
path
)
as
string
;
const
redirect
=
decodeURIComponent
(
redirectPath
);
const
nextData
=
to
.
path
===
redirect
?
{
...
to
,
replace
:
true
}
:
{
path
:
redirect
};
const
nextData
=
to
.
path
===
redirect
?
{
...
omit
(
to
,
[
'
name
'
,
'
params
'
]),
replace
:
true
}
:
{
path
:
redirect
};
permissionStore
.
setDynamicAddedRoute
(
true
);
next
(
nextData
);
// next(nextData);
return
nextData
;
});
}
src/router/routes/basic.ts
浏览文件 @
237e65ea
import
type
{
AppRouteRecordRaw
}
from
'
/@/router/types
'
;
import
{
t
}
from
'
/@/hooks/web/useI18n
'
;
import
{
REDIRECT_NAME
,
LAYOUT
,
EXCEPTION_COMPONENT
}
from
'
/@/router/constant
'
;
import
{
REDIRECT_NAME
,
LAYOUT
,
EXCEPTION_COMPONENT
,
PAGE_NOT_FOUND_NAME
,
}
from
'
/@/router/constant
'
;
// 404 on a page
export
const
PAGE_NOT_FOUND_ROUTE
:
AppRouteRecordRaw
=
{
path
:
'
/:path(.*)*
'
,
name
:
'
ErrorPage
'
,
name
:
PAGE_NOT_FOUND_NAME
,
component
:
LAYOUT
,
meta
:
{
title
:
'
ErrorPage
'
,
...
...
@@ -15,11 +20,12 @@ export const PAGE_NOT_FOUND_ROUTE: AppRouteRecordRaw = {
children
:
[
{
path
:
'
/:path(.*)*
'
,
name
:
'
ErrorPage
'
,
name
:
PAGE_NOT_FOUND_NAME
,
component
:
EXCEPTION_COMPONENT
,
meta
:
{
title
:
'
ErrorPage
'
,
hideBreadcrumb
:
true
,
hideMenu
:
true
,
},
},
],
...
...
src/router/routes/index.ts
浏览文件 @
237e65ea
...
...
@@ -37,4 +37,10 @@ export const LoginRoute: AppRouteRecordRaw = {
};
// Basic routing without permission
export
const
basicRoutes
=
[
LoginRoute
,
RootRoute
,
...
mainOutRoutes
,
REDIRECT_ROUTE
];
export
const
basicRoutes
=
[
LoginRoute
,
RootRoute
,
...
mainOutRoutes
,
REDIRECT_ROUTE
,
PAGE_NOT_FOUND_ROUTE
,
];
src/store/modules/user.ts
浏览文件 @
237e65ea
...
...
@@ -11,6 +11,8 @@ import { doLogout, getUserInfo, loginApi } from '/@/api/sys/user';
import
{
useI18n
}
from
'
/@/hooks/web/useI18n
'
;
import
{
useMessage
}
from
'
/@/hooks/web/useMessage
'
;
import
{
router
}
from
'
/@/router
'
;
import
{
usePermissionStore
}
from
'
/@/store/modules/permission
'
;
import
{
RouteRecordRaw
}
from
'
vue-router
'
;
interface
UserState
{
userInfo
:
Nullable
<
UserInfo
>
;
...
...
@@ -87,10 +89,19 @@ export const useUserStore = defineStore({
const
userInfo
=
await
this
.
getUserInfoAction
();
const
sessionTimeout
=
this
.
sessionTimeout
;
sessionTimeout
&&
this
.
setSessionTimeout
(
false
);
!
sessionTimeout
&&
goHome
&&
(
await
router
.
replace
(
userInfo
.
homePath
||
PageEnum
.
BASE_HOME
));
if
(
sessionTimeout
)
{
this
.
setSessionTimeout
(
false
);
}
else
if
(
goHome
)
{
const
permissionStore
=
usePermissionStore
();
if
(
!
permissionStore
.
isDynamicAddedRoute
)
{
const
routes
=
await
permissionStore
.
buildRoutesAction
();
routes
.
forEach
((
route
)
=>
{
router
.
addRoute
(
route
as
unknown
as
RouteRecordRaw
);
});
permissionStore
.
setDynamicAddedRoute
(
true
);
}
await
router
.
replace
(
userInfo
.
homePath
||
PageEnum
.
BASE_HOME
);
}
return
userInfo
;
}
catch
(
error
)
{
return
Promise
.
reject
(
error
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录