【发布时间】:2017-10-21 02:25:02
【问题描述】:
切换到路由器 v4 和历史 v4.5.1,现在历史监听器不工作
import createBrowserHistory from 'history/createBrowserHistory'
const history = createBrowserHistory()
history.listen((location, action) => {
console.log(action, location.pathname, location.state) // <=== Never happens
})
render(
<Provider store={store}>
<Router history={history}>
...
</Router>
</Provider>,
document.getElementById('root')
)
任何想法为什么它被忽略?
【问题讨论】:
-
您在这里使用的路由器是什么?是浏览器路由器还是路由器?我问这个是因为有些人用这样的命名导入导入 BrowserRouter。
import { BrowserRouter as Router } from 'react-router-dom' -
^ 这就是我正在做的事情
标签: reactjs redux react-router browser-history react-router-v4