我有一个名为App
我的渲染方法中包含以下代码:
<Provider store={store}>
<Router history={history}>
<div>
<Content>
<ListItem onClick={this.onListItemClick}
<Content>
</div>
</Router>
</Provider>
在onListItemClick
里面,我正在history.push(location);
这些是我在代码中包含的以下导入语句:
import { Router} from 'react-router-dom';
import createBrowserHistory from 'history/createBrowserHistory';
然后,我将按照以下方式创建和收听历史记录:
const history = createBrowserHistory();
history.listen(location, action => {
console.log('listen triggered');
});
我有以下出口声明。
export {App, AppState etc}
export default App
从不记录控制台日志语句。
如何确保每次正确触发history.listen
?
版本:
"react-router-dom": "^4.3.1",
"history": "^4.7.2",