reactjs - 使用 React.lazy 的静态路由
问题描述
在使用 React.lazy 时尝试延迟加载静态路由时,我收到以下错误消息。我不知道从这里去哪里?
未捕获的错误:无法在未安装的组件上找到节点。
我猜当我单击它尚未安装的路径时?
这是定义路线的地方。作为测试,我只是加载应用程序最重的部分。我正在使用最新版本的 React 和 React Router-dom。
const AddressValidator = lazy(() => import('views/AddressValidator/ValidationForm'));
const Landing = lazy(() => import('../views/Dashboard/Landing'));
/**
* Contains routes that will be displayed on the navigation bars
*/
const routes = [
{
path: '/dashboard',
sidebarName: 'Dashboard',
navbarName: 'Dashboard',
component: Landing,
icon: Dashboard,
},
{
path: '/email',
sidebarName: 'Email Templates',
navbarName: 'Email Template Manager',
component: EmailListPage,
icon: Email,
subRoutes: false,
},
{
path: '/email/edit',
navbarName: 'Email Details',
sidebarName: 'Edit',
component: EmailDetailsPage,
hidden: true,
},
{
path: '/address',
sidebarName: 'Address Validation',
navbarName: 'Address Validation',
component: AddressValidator,
icon: Shipping,
},
{
path: '/mta',
sidebarName: 'MyTech Assistant',
navbarName: 'MyTech Assistant',
icon: Book,
subRoutes: mtaRoutes,
showLanding: false,
},
{
path: '/lmi',
sidebarName: 'Log Me In',
navbarName: 'LMI Agent Account Creation',
component: UserCreator,
icon: VerifiedUser,
},
{
path: '/user_management',
sidebarName: 'User Management',
navbarName: 'User Management',
component: UserManagement,
icon: People,
},
{
path: '/user_restriction',
sidebarName: 'User Restriction',
navbarName: 'User Restriction',
component: UserRestriction,
icon: Lock,
},
{
path: '/mobile_catalog',
sidebarName: 'Mobile Catalog',
navbarName: 'Mobile Catalog',
component: MobileCatalogExplorer,
icon: '',
},
];
这是 app.js
const hist = createBrowserHistory();
const App = () => (
<Provider store={createStore(reducers)}>
<MsalAuthProvider>
<ModalRoot />
<AlertRoot />
<Suspense fallback={<div>Loading...</div>}>
<Router history={hist}>
<Switch>
{ indexRoutes.map((prop, key) => <ProtectedRoute path={prop.path} component={prop.component} key={key} />)}
</Switch>
</Router>
</Suspense>
</MsalAuthProvider>
</Provider>
);
解决方案
推荐阅读
- python - __getattr__ 的奇怪问题,其中项目字符串在调用期间被更改
- mysql - 将 Solr 文档元信息导出到 MySQL
- python - 如何重复一个字符串直到另一个字符串的长度,包括空格?
- c++ - 更新中的奇怪孔、阴影和旋转出现在 openGL 中
- python - 如何解决 pyTorch 中图像上 CNN 的尺寸不匹配错误?
- docker - Jenkinsfile 管道:从另一个访问一个 docker 容器
- sql - 获取所有可能的条目 SQL Join
- javascript - 将 React-Hook 与重定向和 setTimeout 一起使用
- r - 在 for 循环 (R) 中遍历许多类似名称的文件的最佳方法
- mysql - 将两个 SQL 查询的结果合二为一,但保持分隔形式