Fix routing for childRoutes

This commit is contained in:
Grigorii Desyatnikov 2021-11-29 12:13:09 +03:00
parent 18d70e9aff
commit 0fe010ccdc
1 changed files with 3 additions and 16 deletions

View File

@ -19,7 +19,6 @@ const renderRouteConfig = (
): JSX.Element => {
// Resolve route config object in React Router v3.
const children: React.ReactNode[] = []
console.log("start")
const renderRoute = (item: RouteDefinition, routeContextPath: string) => {
let newContextPath: string
@ -29,9 +28,8 @@ const renderRouteConfig = (
} else {
newContextPath = `${routeContextPath}/${item.path}`
}
//newContextPath = `${routeContextPath}/${item.path}`
newContextPath = newContextPath.replace(/\/+/g, '/')
console.log(newContextPath, item.name)
if (item.redirect) {
const route = (
@ -45,15 +43,7 @@ const renderRouteConfig = (
children.push(route)
} else if (item.component && item.childRoutes) {
console.log(item.name)
const routeConfig = renderRouteConfig(item.component, item.childRoutes, newContextPath)
// (
// <Route
// path={newContextPath}
// >
// {renderRouteConfig(item.component, item.childRoutes, newContextPath)}
// </Route>
// )
children.push(routeConfig)
} else if (item.component) {
@ -66,7 +56,7 @@ const renderRouteConfig = (
}
routes.forEach(item => renderRoute(item, contextPath))
console.log("end", children.length)
// Use Switch as the default container by default
if (!Container) {
return (
@ -75,7 +65,7 @@ const renderRouteConfig = (
</Switch>
)
}
console.log("mega end")
return (
<Container key={contextPath}>
<Switch>
@ -95,15 +85,12 @@ const Router: React.FC<Props> = (props: Props) => {
const { routeConfig, component, baseUrlPath } = props
const preparedRoutes = prepareRoutes(routeConfig)
console.log(preparedRoutes)
//console.log("React",renderRouteConfig(component, preparedRoutes, baseUrlPath))
return (
<BrowserRouter>
{renderRouteConfig(component, preparedRoutes, baseUrlPath)}
</BrowserRouter>
)
//renderRouteConfig(component, preparedRoutes, baseUrlPath)
}
export default Router