dvajs在嵌套路由中动态导入model,报错说‘model’ undefined

https://img3.mukewang.com/5ca81a8600014a3206320778.jpg

以上是路由代码

https://img2.mukewang.com/5ca81a870001fba805970115.jpg

以上是报错信息


SMILET
浏览 682回答 1
1回答

慕后森

routes.map(({path, models, component, ...dynamics},key)) => (&nbsp; &nbsp; if (model) {&nbsp; &nbsp; &nbsp; dynamics.models = () => models();&nbsp; &nbsp; }&nbsp; &nbsp; dynamics.component = () => component();&nbsp; &nbsp; <Router key={key}&nbsp; &nbsp; &nbsp; &nbsp; exact&nbsp; &nbsp; &nbsp; &nbsp; path={path}&nbsp; &nbsp; &nbsp; &nbsp; component={dynamic({&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; app,&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ...dynamics&nbsp; &nbsp; &nbsp; &nbsp; })})你要把model引入。if (model) {&nbsp; dynamics.models = () => models();}dynamics.component = () => component();//相当于:const UserPageComponent = dynamic({&nbsp; app,&nbsp; models: () => [&nbsp; &nbsp; import('./models/users'),&nbsp; ],&nbsp; component: () => import('./routes/UserPage'),});//你需要把model引入你的组件。。。。routes.map(({path, models, component, ...dynamics},key)) => {&nbsp; &nbsp; if (models) {&nbsp; &nbsp; &nbsp; dynamics.models = () => models();&nbsp; &nbsp; }&nbsp; &nbsp; dynamics.component = () => component();&nbsp; &nbsp; return (&nbsp; &nbsp; &nbsp; &nbsp; <Router key={key}&nbsp; &nbsp; &nbsp; &nbsp; exact&nbsp; &nbsp; &nbsp; &nbsp; path={path}&nbsp; &nbsp; &nbsp; &nbsp; component={dynamic({&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; app,&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ...dynamics&nbsp; &nbsp; &nbsp; &nbsp; })}&nbsp; &nbsp; )}见链接
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript