Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
D
dinky
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
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
wangpeng
dinky
Commits
55b9902b
Unverified
Commit
55b9902b
authored
Aug 16, 2023
by
yqwoe
Committed by
GitHub
Aug 16, 2023
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
'fix: 前端路由默认跳转;403页面返回首页 (#2226)
* feat: use-service hooks * fix: 前端路由默认跳转;403页面返回首页
parent
6ab17b57
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
55 additions
and
1 deletion
+55
-1
app.tsx
dinky-web/src/app.tsx
+50
-0
index.tsx
dinky-web/src/pages/Other/403/index.tsx
+5
-1
No files found.
dinky-web/src/app.tsx
View file @
55b9902b
...
@@ -33,6 +33,7 @@ import storage from 'redux-persist/lib/storage';
...
@@ -33,6 +33,7 @@ import storage from 'redux-persist/lib/storage';
import
{
Reducer
,
StoreEnhancer
}
from
'redux'
;
import
{
Reducer
,
StoreEnhancer
}
from
'redux'
;
import
{
API
}
from
"./services/data"
;
import
{
API
}
from
"./services/data"
;
import
{
AccessContextProvider
}
from
'@/hooks/useAccess'
;
import
{
AccessContextProvider
}
from
'@/hooks/useAccess'
;
import
{
Navigate
}
from
'umi'
;
// const isDev = process.env.NODE_ENV === "development";
// const isDev = process.env.NODE_ENV === "development";
const
loginPath
=
API_CONSTANTS
.
LOGIN_PATH
;
const
loginPath
=
API_CONSTANTS
.
LOGIN_PATH
;
...
@@ -40,6 +41,9 @@ const loginPath = API_CONSTANTS.LOGIN_PATH;
...
@@ -40,6 +41,9 @@ const loginPath = API_CONSTANTS.LOGIN_PATH;
const
whiteList
=
[
'/user'
,
'/user/login'
]
const
whiteList
=
[
'/user'
,
'/user/login'
]
let
extraRoutes
;
/**
/**
* 初始化路由鉴权
* 初始化路由鉴权
* @param param0
* @param param0
...
@@ -67,6 +71,7 @@ export async function getInitialState(): Promise<{
...
@@ -67,6 +71,7 @@ export async function getInitialState(): Promise<{
const
fetchUserInfo
=
async
()
=>
const
fetchUserInfo
=
async
()
=>
queryCurrentUser
().
then
((
result
)
=>
{
queryCurrentUser
().
then
((
result
)
=>
{
const
user
=
result
.
datas
.
user
;
const
user
=
result
.
datas
.
user
;
extraRoutes
=
result
.
datas
.
menuList
;
const
currentUser
:
API
.
CurrentUser
=
{
const
currentUser
:
API
.
CurrentUser
=
{
user
:
{
user
:
{
id
:
user
.
id
,
id
:
user
.
id
,
...
@@ -185,3 +190,48 @@ export const dva = {
...
@@ -185,3 +190,48 @@ export const dva = {
},
},
};
};
/***
* 动态修改默认跳转路由
*/
const
patch
=
(
oldrRoutes
,
routes
)
=>
{
oldrRoutes
[
1
].
routes
=
oldrRoutes
[
1
].
routes
.
map
(
route
=>
{
if
(
route
.
routes
&&
route
.
routes
.
length
){
const
redirect
=
routes
.
filter
(
r
=>
r
.
path
.
startsWith
(
route
.
path
))
if
(
redirect
.
length
){
route
.
routes
.
shift
();
route
.
routes
.
unshift
({
path
:
route
.
path
,
element
:
<
Navigate
to=
{
redirect
[
0
].
path
}
/>
})
}
}
return
route
;
})
}
/***
* 动态修改路由
*/
export
function
patchClientRoutes
({
routes
})
{
// 根据 extraRoutes 对 routes 做一些修改
patch
(
routes
,
extraRoutes
);
}
/***
* 动态加载路由
*/
export
function
render
(
oldRender
)
{
const
{
location
}
=
history
;
if
(
location
.
pathname
!==
loginPath
)
{
const
filterMenus
=
(
menus
=
[])
=>
{
return
menus
.
filter
(
menu
=>
menu
.
type
!==
'F'
)
}
queryCurrentUser
().
then
(
res
=>
{
extraRoutes
=
filterMenus
(
res
.
datas
.
menuList
)
oldRender
();
})
}
}
dinky-web/src/pages/Other/403/index.tsx
View file @
55b9902b
...
@@ -17,6 +17,8 @@
...
@@ -17,6 +17,8 @@
import
{
Button
,
Result
}
from
"antd"
;
import
{
Button
,
Result
}
from
"antd"
;
import
{
l
}
from
"@/utils/intl"
;
import
{
l
}
from
"@/utils/intl"
;
import
{
history
}
from
"@umijs/max"
;
export
const
UnAccessible
=
()
=>
{
export
const
UnAccessible
=
()
=>
{
...
@@ -26,7 +28,9 @@ export const UnAccessible = () => {
...
@@ -26,7 +28,9 @@ export const UnAccessible = () => {
title=
"403"
title=
"403"
subTitle=
{
l
(
"app.request.403"
)
}
subTitle=
{
l
(
"app.request.403"
)
}
extra=
{
extra=
{
<
Button
type=
"primary"
>
<
Button
type=
"primary"
onClick=
{
e
=>
{
history
.
push
(
'/'
)
}
}
>
{
l
(
"app.request.back"
)
}
{
l
(
"app.request.back"
)
}
</
Button
>
</
Button
>
}
}
...
...
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