1window.history.pushState("http://example.ca", "Sample Title", "/example/path.html");
2
1// usually all you need
2<Link to="/somewhere"/>
3
4// but you can use a location instead
5const location = {
6 pathname: '/somewhere',
7 state: { fromDashboard: true }
8}
9
10<Link to={location}/>
11<Redirect to={location}/>
12history.push(location)
13history.replace(location)
14
1class Comp extends React.Component {
2 componentDidUpdate(prevProps) {
3 // will be true
4 const locationChanged =
5 this.props.location !== prevProps.location;
6
7 // INCORRECT, will *always* be false because history is mutable.
8 const locationChanged =
9 this.props.history.location !== prevProps.history.location;
10 }
11}
12
13<Route component={Comp} />;
14