Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
C
CivWeb
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
ReactWeb5
CivWeb
Commits
7c9ea365
Commit
7c9ea365
authored
Sep 30, 2021
by
邓晓峰
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: 删除多余路由代码
parent
7eed81cf
Pipeline
#35574
skipped with stages
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
0 additions
and
50 deletions
+0
-50
index.js
src/containers/App/index.js
+0
-50
No files found.
src/containers/App/index.js
View file @
7c9ea365
...
...
@@ -21,56 +21,6 @@ const config = require('../../../config/config');
const
defaultSetting
=
config
.
layout
;
const
createRoute
=
routes
=>
{
return
(
<
Switch
>
{
routes
.
map
((
route
,
index
)
=>
createFixRoute
(
route
,
index
)
)
}
<
Redirect
from
=
'/*'
to
=
'/'
/>
<
/Switch
>
);
};
//该组件通过递归的方式,将所有route中带有children路由的父路由进行解构,最终用createBasicRoute函数来渲染
const
createFixRoute
=
(
route
,
index
)
=>
{
const
{
path
,
component
:
RouteComponent
,
routes
}
=
route
;
if
(
routes
)
{
return
(
<
Route
key
=
{
index
}
path
=
{
path
}
children
=
{
props
=>
{
let
redirectPath
=
null
;
return
<
RouteComponent
{...
props
}
route
=
{
route
}
routes
=
{
route
.
routes
}
params
=
{
route
.
params
}
>
<
Switch
>
{
routes
.
map
((
child
,
index2
)
=>
{
const
{
path
:
childPath
,
redirect
}
=
child
;
if
(
redirect
){
redirectPath
=
childPath
;
}
return
createFixRoute
({...
child
,
path
:
path
+
childPath
},
`
${
index
}
-
${
index2
}
`
);
})}
<
Redirect
from
=
{
`
${
path
}
`
}
to
=
{
`
${
path
}${
redirectPath
||
routes
[
0
].
path
}
`
}
/
>
<
/Switch
>
<
/RouteComponent>
;
}}
/
>
);
}
else
{
return
createBasicRoute
(
route
,
index
);
}
};
const
createBasicRoute
=
(
route
,
index
)
=>
{
// 最基础的Router 用法
const
{
path
,
component
:
Component
}
=
route
;
return
<
Route
exact
key
=
{
index
}
path
=
{
path
}
component
=
{
props
=>
{
return
<
Component
{...
props
}
route
=
{
route
}
routes
=
{
route
.
routes
}
params
=
{
route
.
params
}
/>
;
}}
/>
;
};
function
App
(
props
)
{
const
{
routes
}
=
dyRoutes
(
props
.
menu
);
console
.
log
(
"routes"
,
routes
)
...
...
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