我想在子路径上动态加载模型,因为模型可能非常大,而且
模型有时是动态生成的(使用动态namespace
)。
the target
这是我的代码。我从app
/src/index.js
import React from 'react'
import modelExtend from 'dva-model-extend'
import { Route, Switch, Redirect } from 'react-router-dom'
import dynamic from 'dva/dynamic'
import app from '../../../index'
function StepRoutes({ match }) {
const id = match.params.id
const routes = [{
path: `${match.url}/class-maintenance`,
models: () => [modelExtend(ClassBasicModel, { namespace: `class-maintenance-${id}` })],
component: () => import('./ClassMaintenance'),
}, {
path: `${match.url}/course-selection`,
models: () => [import('./CourseSelection/basicModel')],
component: () => import('../Steps/CourseSelection'),
}]
return (
<Switch>
<Route exact path={match.url} render={() => (<Redirect to={`${match.url}/class-maintenance`} />)} />
{
routes.map(({ path, ...dynamics }, index) => (
<Route
key={index}
exact
path={path}
component={dynamic({ app, ...dynamics })}
/>
))
}
</Switch>
)
}
export default StepRoutes
2.然后,当切换到路线但Warning
时,模型进行了动态加载。我怎么解决这个问题 ?
the error