实现经过单个component 单个router经过相应的标识对应产生不一样model实现数据包分离,model namespce将会覆盖基础的Model,其中的model[state|subscriptions|effects|reducers] 将经过Object.assign进行复制( Object.assign({},obj,obj1) )将源对象里面的属性添加到目标对象中去,若二者的属性名有冲突,后面的将会覆盖前面的。javascript
在子路由中动态导入model, 由于model比较大, 须要在这个子页面加载的时候加载model, 另外这个能够经过modelExtend 动态生成model(即动态生成namespace)java
在原文中的定义app
The model.namespace will be overrided by latter model.
model[state|subscriptions|effects|reducers] will be merged as Object.assign.
model.state will be overrided be latter model if it isn't an object.ide
imoport BaseModel from '../model/BaseModel' import dynamic from 'dva/dynamic';// 经过dynamic实现动态加载路由、model import modelExtend from 'dva-model-extend'; const dynamicWrapperCreateNewModel = (app, component, history) => dynamic({ app, models: () => [modelExtend(BaseModel, { namespace: `createNewModel-${history.location.state.id}` })], component, });
{ name: '路由', path: 'BaseInstance', component: dynamicWrapperCreateTab(app, () => import('../routes/OnlyRouter/BillBaseInstance'), history), },
@connect(state => ({ myModel: state[`createNewModel-${history.state.state.id}`], }))
经过Link的方式传递idthis
import { Link } from 'dva/router'; <Link to={{ pathname: this.props.path, // 传递path state: { id: this.props.pathId }, 传递id 标识 }} >
经过routerRedux的方式传递idspa
import { routerRedux } from 'dva/router'; yield put(routerRedux.replace({ pathname: '/dashboard/BaseInstance', state: { // 标识 id: '0B64AF10-F1D0-6CD0-647F-160C50326F9D', }, }));