我目前正在使用react-router来处理react-redux,我的页面之一需要知道用户单击哪个页面以定向到该新页面。
有没有一种方法可以通过react-router获得有关上一页URL的信息?
您应该能够将先前的位置保存在getDerivedStateFromProps方法中。
static getDerivedStateFromProps(nextProps, prevState) {
if (prevState.location === //your path){
...
}
return null;
};
此处提供更多信息: https : //reactjs.org/docs/react-component.html#static-getderivedstatefromprops