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
51e95274
Commit
51e95274
authored
Sep 26, 2021
by
邓晓峰
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: 修复renderRoutes methods
parent
293458fb
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
67 additions
and
39 deletions
+67
-39
index.js
src/containers/App/index.js
+4
-4
BasicLayout1.js
src/layouts/BasicLayout1.js
+2
-1
UserLayout.js
src/layouts/UserLayout.js
+1
-1
routes.js
src/utils/routes.js
+60
-33
No files found.
src/containers/App/index.js
View file @
51e95274
...
...
@@ -2,9 +2,9 @@ import React, { Suspense } from 'react';
import
{
Helmet
}
from
'react-helmet'
;
import
{
connect
}
from
'react-redux'
;
import
{
renderRoutes
}
from
'react-router-config'
;
// import { RouteWithSubRoutes, renderRoutes
} from '../../utils/routes'
import
BootPage
from
'../../pages/bootpage'
;
//
import { renderRoutes } from 'react-router-config';
import
{
renderRoutes
}
from
'../../utils/routes'
//
import BootPage from '../../pages/bootpage';
import
{
Router
,
Switch
,
...
...
@@ -13,7 +13,7 @@ import {
}
from
'@wisdom-utils/runtime'
;
import
{
dyRoutes
}
from
'../../routes/config'
;
import
routeContext
from
'@ant-design/pro-layout/lib/RouteContext'
;
//
import routeContext from '@ant-design/pro-layout/lib/RouteContext';
// import { Route } from 'react-router-dom';
const
pkg
=
require
(
'../../../package.json'
);
...
...
src/layouts/BasicLayout1.js
View file @
51e95274
...
...
@@ -18,7 +18,8 @@ import {
Tooltip
}
from
'antd'
;
// import { RouteWithSubRoutes, renderRoutes } from '../utils/routes';
import
{
renderRoutes
}
from
'react-router-config'
;
// import { renderRoutes } from 'react-router-config';
import
{
renderRoutes
}
from
'../utils/routes'
import
{
PageContainer
}
from
'@ant-design/pro-layout'
;
import
Icon
from
'@ant-design/icons'
;
import
{
store
}
from
'microser-data'
;
...
...
src/layouts/UserLayout.js
View file @
51e95274
...
...
@@ -5,7 +5,7 @@ import {
HelmetProvider
,
}
from
'react-helmet-async'
;
import
{
connect
}
from
'react-redux'
;
import
{
renderRoutes
}
from
'
react-router-config
'
;
import
{
renderRoutes
}
from
'
../utils/routes
'
;
import
{
getMenuData
,
...
...
src/utils/routes.js
View file @
51e95274
import
{
transformURL
}
from
'./utils'
;
import
{
Route
,
Switch
}
from
'@wisdom-utils/runtime'
;
import
{
matchPath
,
Route
,
Switch
}
from
'react-router'
;
import
React
,
{
Suspense
,
Fragment
}
from
'react'
;
export
const
isURL
=
function
(
url
)
{
// eslint-disable-next-line no-useless-escape
...
...
@@ -149,35 +147,64 @@ export function RouteWithSubRoutes(route) {
<
Route
path
=
{
route
.
path
}
render
=
{
props
=>
(
<
route
.
component
{...
props
}
route
=
{
route
}
routes
=
{
route
.
routes
}
params
=
{
route
.
params
}
/>
)
}></
Route
>
)
}
export
function
renderRoutes
(
routes
)
{
return
routes
.
map
((
route
,
index
)
=>
(
<
Route
key
=
{
index
}
path
=
{
route
.
path
}
exact
=
{
route
.
exact
}
render
=
{(
props
)
=>
{
// 利用render 方法处理
if
(
route
.
routes
){
return
(
<>
<
route
.
component
{...
props
}
route
=
{
route
}
routes
=
{
route
.
routes
}
params
=
{
route
.
params
}
><
/route.component
>
<
Switch
>
{
route
.
routes
.
map
((
child
,
i
)
=>
(
RouteWithSubRoutes
(
child
)
))
}
{
/* <Redirect to={route.routes[0].path}></Redirect> // 子路由找不到,重定向到第一个子路由 */
}
<
/Switch
>
<
/
>
)
}
else
{
return
(
<
route
.
component
{...
props
}
route
=
{
route
}
routes
=
{
route
.
routes
}
params
=
{
route
.
params
}
><
/route.component
>
)
function
matchRoutes
(
routes
,
pathname
,
branch
)
{
if
(
branch
===
void
0
)
{
branch
=
[];
}
routes
.
some
(
function
(
route
)
{
var
match
=
route
.
path
?
matchPath
(
pathname
,
route
)
:
branch
.
length
?
branch
[
branch
.
length
-
1
].
match
// use parent match
:
Router
.
computeRootMatch
(
pathname
);
// use default "root" match
if
(
match
)
{
branch
.
push
({
route
:
route
,
match
:
match
});
if
(
route
.
routes
)
{
matchRoutes
(
route
.
routes
,
pathname
,
branch
);
}
}}
/
>
))
}
return
match
;
});
return
branch
;
}
function
renderRoutes
(
routes
,
extraProps
,
switchProps
)
{
if
(
extraProps
===
void
0
)
{
extraProps
=
{};
}
if
(
switchProps
===
void
0
)
{
switchProps
=
{};
}
return
routes
?
React
.
createElement
(
Switch
,
switchProps
,
routes
.
map
(
function
(
route
,
i
)
{
return
React
.
createElement
(
Route
,
{
key
:
route
.
key
||
i
,
path
:
route
.
path
,
exact
:
route
.
exact
,
strict
:
route
.
strict
,
render
:
function
render
(
props
)
{
return
route
.
render
?
route
.
render
(
Object
.
assign
({},
props
,
{},
extraProps
,
{
routes
:
route
.
routes
,
params
:
route
.
params
,
route
:
route
}))
:
React
.
createElement
(
route
.
component
,
Object
.
assign
({},
props
,
extraProps
,
{
route
:
route
,
routes
:
route
.
routes
,
params
:
route
.
params
,
}));
}
});
}))
:
null
;
}
export
{
renderRoutes
,
matchPath
}
export
default
generRotes
;
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