我正在将 react-router-4.0.0-beta.4
与 redux 一起使用,我试图找出在路由更改时调度操作的最佳方法。我看到几个版本之前有一个 API/事件 Hook here 。但我看到它现在已经消失了。尝试做与 redux-router
所做的现代等效的事情。
最佳答案
似乎分派(dispatch)操作的最佳方法是在组件的 componentWillMount()
、componentDidMount()
或 componentWillUnmount()
处执行此操作方法。
忽略下面的内容
有 onEnter
属性。喜欢这里comet-frontend
onEnter(nextState, replace, callback?)
Called when a route is about to be entered. It provides the next router state and a function to redirect to another path. this will be the route instance that triggered the hook. https://github.com/ReactTraining/react-router/blob/master/docs/API.md#onenternextstate-replace-callback
但是,仍然有 onChange 属性,完全按照您所描述的方式进行。也许告诉我们您的问题到底是什么。因为看起来你做错了什么。
关于reactjs - 如何使用 React Router v4 调度位置变化时的操作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42478271/