我正在使用最新的React Router(4)版本。我有一个动态配置我的路线,就像它在教程中所述。它工作正常,但是当我尝试添加404路径时(就像在本教程中那样),它会在加载具有正确路径的任何普通组件之前,开始显示此404页面。在动态路由的情况下反应路由器4 404路径
如果路径不存在,404路由将正常工作。
在移动的情况下允许的路由配置)
首先 - 404组件显示(我不知道为什么) 二 - 普通组件显示和404组件已经消失了。
有没有人有任何信息如何解决这个问题?感谢您的任何信息!
这是我的路由配置。
import React from "react";
import { Route, Switch } from "react-router-dom";
import { Config } from "shared/services";
import lazyRoute from "./lazyRoute";
const navScheme = Config.navigationScheme;
const COMPLEX_ROUTES = route => {
console.log("routesss ->> ", route);
return (
<Switch >
<Route path={route.path} exact={!!route.exact} render={props => (
// pass the sub-routes down to keep nesting
<route.component {...props} routes={route.routes}/>
)}/>
</Switch>
);
};
const generateRoutes = routes => routes.map((route, i) => (
<COMPLEX_ROUTES key={i} {...route}/>
));
const PLATFORM_CHILD_ROUTES = [
{
path : navScheme.platform,
component : lazyRoute(() => import("../../modules/home/Home.module")),
exact : true
}
];
const ROUTES = [
{
path : navScheme.root,
component : lazyRoute(() => import("../../modules/landing-page/LandingPage.module")),
exact : true
},
{
path : navScheme.platform,
component : lazyRoute(() => import("../components/Platform")),
routes : PLATFORM_CHILD_ROUTES
},
{
path : "*",
component : lazyRoute(() => import("../../modules/errors/Error404.module"))
},
];
export { generateRoutes, ROUTES };
你如何做到这一点lazyRoute()? – Ventura