我用的是react路由.我想检测我来自的上一个页面(在同一个应用程序中).我有路由在我的上下文中.但是,我没有在路由对象上看到任何属性,比如"前一条路径"或历史记录.我该怎么做?
我用的是react路由.我想检测我来自的上一个页面(在同一个应用程序中).我有路由在我的上下文中.但是,我没有在路由对象上看到任何属性,比如"前一条路径"或历史记录.我该怎么做?
可以在componentWillReceiveProps
生命周期方法中保存上一条路径.逻辑与react-router
份文档中的troubleshooting section份非常接近.
<Route component={App}>
{/* ... other routes */}
</Route>
const App = React.createClass({
getInitialState() {
return { prevPath: '' }
},
componentWillReceiveProps(nextProps) {
if (nextProps.location !== this.props.location) {
this.setState({ prevPath: this.props.location })
}
}
})
最近,从州政府获取信息.