1

I am currently working on react-redux with react-router, and one of my page need to know which page user clicked to direct to this new page.

Is there a way that I can get the information about the url of previous page by react-router?

SS77nmp
  • 23
  • 3

1 Answers1

0

You should be able to save the previous location in the getDerivedStateFromProps method.

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

More info here: https://reactjs.org/docs/react-component.html#static-getderivedstatefromprops

sylar12
  • 107
  • 1
  • 8