Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
N
najiu-admin-template
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
najiu-frontend
najiu-admin-template
Commits
237e65ea
Commit
237e65ea
authored
Jul 14, 2021
by
无木
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: resolving `Vue Router warn`
移除因为动态加载路由而产生的vue-router警告
parent
6350224a
Changes
6
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
56 additions
and
25 deletions
+56
-25
CHANGELOG.zh_CN.md
CHANGELOG.zh_CN.md
+2
-1
constant.ts
src/router/constant.ts
+2
-0
permissionGuard.ts
src/router/guard/permissionGuard.ts
+21
-16
basic.ts
src/router/routes/basic.ts
+9
-3
index.ts
src/router/routes/index.ts
+7
-1
user.ts
src/store/modules/user.ts
+15
-4
No files found.
CHANGELOG.zh_CN.md
View file @
237e65ea
...
@@ -22,11 +22,12 @@
...
@@ -22,11 +22,12 @@
-
修复悬停触发模式下左侧混合菜单会在没有子菜单且被激活时直接跳转路由
-
修复悬停触发模式下左侧混合菜单会在没有子菜单且被激活时直接跳转路由
-
**Breadcrumb**
修复带有重定向的菜单点击无法跳转的问题
-
**Breadcrumb**
修复带有重定向的菜单点击无法跳转的问题
-
**Markdown**
修复初始化异常以及不能正确地动态设置 value 的问题
-
**Markdown**
修复初始化异常以及不能正确地动态设置 value 的问题
-
**Modal**
确保 props 正确被传递
-
**其它**
-
**其它**
-
修复菜单默认折叠的配置不起作用的问题
-
修复菜单默认折叠的配置不起作用的问题
-
修复
`safari`
浏览器报错导致网站打不开
-
修复
`safari`
浏览器报错导致网站打不开
-
修复在 window 上,拉取代码后 eslint 因 endOfLine 而保错问题
-
修复在 window 上,拉取代码后 eslint 因 endOfLine 而保错问题
-
**Modal**
确保 props 正确被传递
-
修复因动态路由而产生的
`Vue Router warn`
### 🎫 Chores
### 🎫 Chores
...
...
src/router/constant.ts
View file @
237e65ea
...
@@ -2,6 +2,8 @@ export const REDIRECT_NAME = 'Redirect';
...
@@ -2,6 +2,8 @@ export const REDIRECT_NAME = 'Redirect';
export
const
PARENT_LAYOUT_NAME
=
'
ParentLayout
'
;
export
const
PARENT_LAYOUT_NAME
=
'
ParentLayout
'
;
export
const
PAGE_NOT_FOUND_NAME
=
'
PageNotFound
'
;
export
const
EXCEPTION_COMPONENT
=
()
=>
import
(
'
../views/sys/exception/Exception.vue
'
);
export
const
EXCEPTION_COMPONENT
=
()
=>
import
(
'
../views/sys/exception/Exception.vue
'
);
/**
/**
...
...
src/router/guard/permissionGuard.ts
View file @
237e65ea
...
@@ -8,6 +8,7 @@ import { useUserStoreWithOut } from '/@/store/modules/user';
...
@@ -8,6 +8,7 @@ import { useUserStoreWithOut } from '/@/store/modules/user';
import
{
PAGE_NOT_FOUND_ROUTE
}
from
'
/@/router/routes/basic
'
;
import
{
PAGE_NOT_FOUND_ROUTE
}
from
'
/@/router/routes/basic
'
;
import
{
RootRoute
}
from
'
/@/router/routes
'
;
import
{
RootRoute
}
from
'
/@/router/routes
'
;
import
{
omit
}
from
'
lodash-es
'
;
const
LOGIN_PATH
=
PageEnum
.
BASE_LOGIN
;
const
LOGIN_PATH
=
PageEnum
.
BASE_LOGIN
;
...
@@ -18,26 +19,20 @@ const whitePathList: PageEnum[] = [LOGIN_PATH];
...
@@ -18,26 +19,20 @@ const whitePathList: PageEnum[] = [LOGIN_PATH];
export
function
createPermissionGuard
(
router
:
Router
)
{
export
function
createPermissionGuard
(
router
:
Router
)
{
const
userStore
=
useUserStoreWithOut
();
const
userStore
=
useUserStoreWithOut
();
const
permissionStore
=
usePermissionStoreWithOut
();
const
permissionStore
=
usePermissionStoreWithOut
();
router
.
beforeEach
(
async
(
to
,
from
,
next
)
=>
{
router
.
beforeEach
(
async
(
to
,
from
)
=>
{
// 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
(
if
(
from
.
path
===
ROOT_PATH
&&
from
.
path
===
ROOT_PATH
&&
to
.
path
===
PageEnum
.
BASE_HOME
&&
to
.
path
===
PageEnum
.
BASE_HOME
&&
userStore
.
getUserInfo
.
homePath
&&
userStore
.
getUserInfo
.
homePath
&&
userStore
.
getUserInfo
.
homePath
!==
PageEnum
.
BASE_HOME
userStore
.
getUserInfo
.
homePath
!==
PageEnum
.
BASE_HOME
)
{
)
{
next
(
userStore
.
getUserInfo
.
homePath
);
//
next(userStore.getUserInfo.homePath);
return
;
return
userStore
.
getUserInfo
.
homePath
;
}
}
// Whitelist can be directly entered
// Whitelist can be directly entered
if
(
whitePathList
.
includes
(
to
.
path
as
PageEnum
))
{
if
(
whitePathList
.
includes
(
to
.
path
as
PageEnum
))
{
next
();
//
next();
return
;
return
;
}
}
...
@@ -47,7 +42,7 @@ export function createPermissionGuard(router: Router) {
...
@@ -47,7 +42,7 @@ export function createPermissionGuard(router: Router) {
if
(
!
token
)
{
if
(
!
token
)
{
// You can access without permission. You need to set the routing meta.ignoreAuth to true
// You can access without permission. You need to set the routing meta.ignoreAuth to true
if
(
to
.
meta
.
ignoreAuth
)
{
if
(
to
.
meta
.
ignoreAuth
)
{
next
();
//
next();
return
;
return
;
}
}
...
@@ -62,12 +57,18 @@ export function createPermissionGuard(router: Router) {
...
@@ -62,12 +57,18 @@ export function createPermissionGuard(router: Router) {
redirect
:
to
.
path
,
redirect
:
to
.
path
,
};
};
}
}
next
(
redirectData
);
//next(redirectData);
return
;
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
)
{
if
(
permissionStore
.
getIsDynamicAddedRoute
)
{
next
();
//
next();
return
;
return
;
}
}
...
@@ -79,8 +80,12 @@ export function createPermissionGuard(router: Router) {
...
@@ -79,8 +80,12 @@ export function createPermissionGuard(router: Router) {
const
redirectPath
=
(
from
.
query
.
redirect
||
to
.
path
)
as
string
;
const
redirectPath
=
(
from
.
query
.
redirect
||
to
.
path
)
as
string
;
const
redirect
=
decodeURIComponent
(
redirectPath
);
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
);
permissionStore
.
setDynamicAddedRoute
(
true
);
next
(
nextData
);
// next(nextData);
return
nextData
;
});
});
}
}
src/router/routes/basic.ts
View file @
237e65ea
import
type
{
AppRouteRecordRaw
}
from
'
/@/router/types
'
;
import
type
{
AppRouteRecordRaw
}
from
'
/@/router/types
'
;
import
{
t
}
from
'
/@/hooks/web/useI18n
'
;
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
// 404 on a page
export
const
PAGE_NOT_FOUND_ROUTE
:
AppRouteRecordRaw
=
{
export
const
PAGE_NOT_FOUND_ROUTE
:
AppRouteRecordRaw
=
{
path
:
'
/:path(.*)*
'
,
path
:
'
/:path(.*)*
'
,
name
:
'
ErrorPage
'
,
name
:
PAGE_NOT_FOUND_NAME
,
component
:
LAYOUT
,
component
:
LAYOUT
,
meta
:
{
meta
:
{
title
:
'
ErrorPage
'
,
title
:
'
ErrorPage
'
,
...
@@ -15,11 +20,12 @@ export const PAGE_NOT_FOUND_ROUTE: AppRouteRecordRaw = {
...
@@ -15,11 +20,12 @@ export const PAGE_NOT_FOUND_ROUTE: AppRouteRecordRaw = {
children
:
[
children
:
[
{
{
path
:
'
/:path(.*)*
'
,
path
:
'
/:path(.*)*
'
,
name
:
'
ErrorPage
'
,
name
:
PAGE_NOT_FOUND_NAME
,
component
:
EXCEPTION_COMPONENT
,
component
:
EXCEPTION_COMPONENT
,
meta
:
{
meta
:
{
title
:
'
ErrorPage
'
,
title
:
'
ErrorPage
'
,
hideBreadcrumb
:
true
,
hideBreadcrumb
:
true
,
hideMenu
:
true
,
},
},
},
},
],
],
...
...
src/router/routes/index.ts
View file @
237e65ea
...
@@ -37,4 +37,10 @@ export const LoginRoute: AppRouteRecordRaw = {
...
@@ -37,4 +37,10 @@ export const LoginRoute: AppRouteRecordRaw = {
};
};
// Basic routing without permission
// 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
View file @
237e65ea
...
@@ -11,6 +11,8 @@ import { doLogout, getUserInfo, loginApi } from '/@/api/sys/user';
...
@@ -11,6 +11,8 @@ import { doLogout, getUserInfo, loginApi } from '/@/api/sys/user';
import
{
useI18n
}
from
'
/@/hooks/web/useI18n
'
;
import
{
useI18n
}
from
'
/@/hooks/web/useI18n
'
;
import
{
useMessage
}
from
'
/@/hooks/web/useMessage
'
;
import
{
useMessage
}
from
'
/@/hooks/web/useMessage
'
;
import
{
router
}
from
'
/@/router
'
;
import
{
router
}
from
'
/@/router
'
;
import
{
usePermissionStore
}
from
'
/@/store/modules/permission
'
;
import
{
RouteRecordRaw
}
from
'
vue-router
'
;
interface
UserState
{
interface
UserState
{
userInfo
:
Nullable
<
UserInfo
>
;
userInfo
:
Nullable
<
UserInfo
>
;
...
@@ -87,10 +89,19 @@ export const useUserStore = defineStore({
...
@@ -87,10 +89,19 @@ export const useUserStore = defineStore({
const
userInfo
=
await
this
.
getUserInfoAction
();
const
userInfo
=
await
this
.
getUserInfoAction
();
const
sessionTimeout
=
this
.
sessionTimeout
;
const
sessionTimeout
=
this
.
sessionTimeout
;
sessionTimeout
&&
this
.
setSessionTimeout
(
false
);
if
(
sessionTimeout
)
{
!
sessionTimeout
&&
this
.
setSessionTimeout
(
false
);
goHome
&&
}
else
if
(
goHome
)
{
(
await
router
.
replace
(
userInfo
.
homePath
||
PageEnum
.
BASE_HOME
));
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
;
return
userInfo
;
}
catch
(
error
)
{
}
catch
(
error
)
{
return
Promise
.
reject
(
error
);
return
Promise
.
reject
(
error
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment