Commit 7c9ea365 authored by 邓晓峰's avatar 邓晓峰

fix: 删除多余路由代码

parent 7eed81cf
Pipeline #35574 skipped with stages
......@@ -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)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment