main.js 727 B

123456789101112131415161718192021222324252627282930
  1. import { routerRedux } from 'dva/router'
  2. export default {
  3. namespace: 'main',
  4. state: {
  5. currentPage: ''
  6. },
  7. reducers: {
  8. setPage(state, action) {
  9. return { state, currentPage: action.page || 'home' };
  10. }
  11. },
  12. effects: {
  13. * redirect (action, { put }) {
  14. const path = action.path;
  15. yield put(routerRedux.push(path || '/'));
  16. },
  17. },
  18. subscriptions: {
  19. setup({ dispatch, history }) {
  20. return history.listen(({ pathname, query }) => {
  21. console.log(pathname);
  22. let page = pathname.match(/\/(\w*)/)[1];
  23. dispatch({ type: 'setPage', page });
  24. })
  25. }
  26. }
  27. };