Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
A
ant-design-pro
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
duanledexianxianxian
ant-design-pro
Commits
fea90487
Commit
fea90487
authored
Sep 11, 2018
by
陈帅
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix #2157 add redirect when no login
parent
1d8e1d91
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
17 additions
and
19 deletions
+17
-19
config/router.config.js
config/router.config.js
+3
-0
src/components/GlobalHeader/RightContent.js
src/components/GlobalHeader/RightContent.js
+1
-1
src/locales/en-US.js
src/locales/en-US.js
+1
-0
src/locales/zh-CN.js
src/locales/zh-CN.js
+1
-0
src/pages/Authorized.js
src/pages/Authorized.js
+11
-18
No files found.
config/router.config.js
View file @
fea90487
...
...
@@ -15,6 +15,7 @@ export default [
path
:
'
/
'
,
component
:
'
../layouts/BasicLayout
'
,
Routes
:
[
'
src/pages/Authorized
'
],
authority
:
[
'
admin
'
,
'
user
'
],
routes
:
[
// dashboard
{
path
:
'
/
'
,
redirect
:
'
/dashboard/analysis
'
},
...
...
@@ -82,6 +83,7 @@ export default [
{
path
:
'
/form/advanced-form
'
,
name
:
'
advancedform
'
,
authority
:
[
'
admin
'
],
component
:
'
./Forms/AdvancedForm
'
,
},
],
...
...
@@ -149,6 +151,7 @@ export default [
{
path
:
'
/profile/advanced
'
,
name
:
'
advanced
'
,
authority
:
[
'
admin
'
],
component
:
'
./Profile/AdvancedProfile
'
,
},
],
...
...
src/components/GlobalHeader/RightContent.js
View file @
fea90487
...
...
@@ -74,7 +74,7 @@ export default class GlobalHeaderRight extends PureComponent {
<
Menu
.
Divider
/>
<
Menu
.
Item
key
=
"
logout
"
>
<
Icon
type
=
"
logout
"
/>
退出登录
<
FormattedMessage
id
=
"
menu.account.logout
"
defaultMessage
=
"
logout
"
/>
<
/Menu.Item
>
<
/Menu
>
);
...
...
src/locales/en-US.js
View file @
fea90487
...
...
@@ -35,6 +35,7 @@ export default {
'
menu.account.center
'
:
'
Account Center
'
,
'
menu.account.settings
'
:
'
Account Settings
'
,
'
menu.account.trigger
'
:
'
Trigger Error
'
,
'
menu.account.logout
'
:
'
Logout
'
,
'
app.home.introduce
'
:
'
introduce
'
,
'
app.analysis.test
'
:
'
Gongzhuan No.{no} shop
'
,
'
app.analysis.introduce
'
:
'
Introduce
'
,
...
...
src/locales/zh-CN.js
View file @
fea90487
...
...
@@ -37,6 +37,7 @@ export default {
'
menu.account.center
'
:
'
个人中心
'
,
'
menu.account.settings
'
:
'
个人设置
'
,
'
menu.account.trigger
'
:
'
触发报错
'
,
'
menu.account.logout
'
:
'
退出登录
'
,
'
app.home.introduce
'
:
'
介绍
'
,
'
app.analysis.test
'
:
'
工专路 {no} 号店
'
,
'
app.analysis.introduce
'
:
'
指标说明
'
,
...
...
src/pages/Authorized.js
View file @
fea90487
...
...
@@ -2,24 +2,15 @@ import React from 'react';
import
RenderAuthorized
from
'
@/components/Authorized
'
;
import
Exception
from
'
@/components/Exception
'
;
import
{
getAuthority
}
from
'
@/utils/authority
'
;
import
{
matchRoutes
}
from
'
react-router-config
'
;
import
intersection
from
'
lodash/intersection
'
;
import
{
formatMessage
}
from
'
umi/locale
'
;
import
Link
from
'
umi/link
'
;
import
Redirect
from
'
umi/redirect
'
;
const
Authorized
=
RenderAuthorized
(
getAuthority
());
const
Authority
=
getAuthority
();
const
Authorized
=
RenderAuthorized
(
Authority
);
export
default
({
children
,
route
,
location
})
=>
{
const
routes
=
matchRoutes
(
route
.
routes
,
location
.
pathname
);
const
authorities
=
[];
routes
.
forEach
(
item
=>
{
if
(
Array
.
isArray
(
item
.
route
.
authority
)
&&
item
.
route
.
authority
.
length
)
{
authorities
.
push
(
item
.
route
.
authority
);
}
else
if
(
typeof
item
.
route
.
authority
===
'
string
'
&&
item
.
route
.
authority
)
{
authorities
.
push
([
item
.
route
.
authority
]);
}
});
const
noMatch
=
(
export
default
({
children
})
=>
{
let
noMatch
=
(
<
Exception
type
=
"
403
"
desc
=
{
formatMessage
({
id
:
'
app.exception.description.403
'
})}
...
...
@@ -27,11 +18,13 @@ export default ({ children, route, location }) => {
backText
=
{
formatMessage
({
id
:
'
app.exception.back
'
})}
/
>
);
// if Authority === ['guest'] redirect to /user/login
// You can implement the logic here.
if
(
Authority
.
join
(
''
)
===
'
guest
'
)
{
noMatch
=
<
Redirect
to
=
"
/user/login
"
/>
;
}
return
(
<
Authorized
authority
=
{
authorities
.
length
===
0
?
undefined
:
intersection
(...
authorities
)}
noMatch
=
{
noMatch
}
>
<
Authorized
authority
=
{
children
.
props
.
route
.
authority
}
noMatch
=
{
noMatch
}
>
{
children
}
<
/Authorized
>
);
...
...
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