| 123456789101112131415161718192021222324252627282930 |
- import { routerRedux } from 'dva/router'
- export default {
- namespace: 'main',
- state: {
- currentPage: ''
- },
- reducers: {
- setPage(state, action) {
- return { state, currentPage: action.page || 'home' };
- }
- },
- effects: {
- * redirect (action, { put }) {
- const path = action.path;
- yield put(routerRedux.push(path || '/'));
- },
- },
- subscriptions: {
- setup({ dispatch, history }) {
- return history.listen(({ pathname, query }) => {
- console.log(pathname);
- let page = pathname.match(/\/(\w*)/)[1];
- dispatch({ type: 'setPage', page });
- })
- }
- }
- };
|