如何通过React-Router获取我来自的URL

问题描述 投票:1回答:1

我目前正在使用react-router来处理react-redux,我的页面之一需要知道用户单击哪个页面以定向到该新页面。

有没有一种方法可以通过react-router获得有关上一页URL的信息?

typescript react-redux react-router-dom
1个回答
0
投票

您应该能够将先前的位置保存在getDerivedStateFromProps方法中。

static getDerivedStateFromProps(nextProps, prevState) {
    if (prevState.location === //your path){
        ...
    }
    return null;
};

此处提供更多信息: https : //reactjs.org/docs/react-component.html#static-getderivedstatefromprops

© www.soinside.com 2019 - 2024. All rights reserved.