我想在React Router中为组件添加预取,但是当前该组件是动态导入。添加webpackprefetch = true不起作用。因此想知道将webpackprefetch = true添加到React路由器的最佳方法是什么。
我尝试使用:
const SCHEDULES = () => import(/* webpackPrefetch: true / / webpackChunkName: "SchedulesPage" */ "./schedules/Schedules");
但这不会创建组件。
当前代码:
<Switch>
{ /* Schedules page */ }
<Route exact path={ `${match.url}/schedules` } component={ Schedules } />
</Switch>
const Schedules = (props: any) => (
<DynamicRouteImport load={ () => import(/* webpackChunkName: "SchedulesPage" */ /* webpackPrefetch: true */ "./schedules/Schedules") }>
{ (Component: any) => Component === null
? <DynamicRouteSpinner />
: <><GlobalCommandBar /><Component {...props} /></> }
</DynamicRouteImport>
);