dva学习---在model的effects做路由跳转

在前面的router中可以看到,路由在组件中的跳转有很多种方式,那么怎么在model中处理完数据后在实现跳转呢?方法如下:

import {routerRedux} from 'dva/router'
export default {
  namespace: 'example',
  state: {},
  effects: {
    *fetch({ payload }, { call, put,select }) {  // eslint-disable-line
      yield put({ type: 'save' });
      yield.put(routerRedux.push('/'))  //这里可以跳转到根目录为'/'的页面
      // yield.put(routerRedux.push({
      //   pathname:"/",   //这有这个参数的话地址就是:localhost:8000
      //   hash:"vison"    //这里是一个hash值,地址就变成了: localhost:8000/#vison
      // }))
    },
  },
  reducers: {
    save(state, action) {
      return { ...state, ...action.payload };
    },
  },
};

猜你喜欢

转载自blog.csdn.net/weixin_40792878/article/details/82052097