为什么没有反应-roule-redux记录初始页面加载

时间:2018-06-01 10:53:05

标签: javascript reactjs redux react-router-redux

我正在为应用添加一点分析跟踪,并注意到我在努力理解的react-router-redux和redux-saga-router之间存在差异:

这是我用来注销react-router-redux检测到的路由操作的代码的简化版本:

import React from 'react';
import { Router, browserHistory } from 'react-router';
import { syncHistoryWithStore } from 'react-router-redux';

import { getStore } from './common/AppStore.js';

const store = getStore();
const history = syncHistoryWithStore(browserHistory, store);

history.listen(location => {
  // this doesn't log the POP action on the initial page load
  console.log('react-router-redux history: ', location);
});

这里有一些代码试图用redux-saga-router做类似的事情:

import { browserHistory as history } from 'react-router';
import { router } from 'redux-saga-router';

// for now this will ensure we bootstrap the app on each route
const options = {
  matchAll: true,
  *beforeRouteChange({ id, section, subsection }) {
    // this DOES log the initial POP action on page load - but then also incorrectly identifies all future PUSH actions and POP actions
    console.log('redux-saga-router history: ', history.getCurrentLocation());
  },
};

export default function* routesSaga() {
  yield fork(router, history, routes, options);
}

因此,在准确报告PUSH与POP的关系方面,react-router-redux领先,但由于无法报告初始页面加载POP动作,我认为我无法使用它。

我错过了什么吗? react-router-redux应该报告初始页面加载吗?如果没有,为什么redux-saga-router错误地报告POP应该报告PUSH?

以下是初始页面加载和后续路由操作的日志记录结果的屏幕截图:

https://puu.sh/Ax47o/e745d825dc.png

0 个答案:

没有答案