history.replace code example
Example 1: javascript window.history.pushState
window.history.pushState("http://example.ca", "Sample Title", "/example/path.html");
Example 2: this.props.history.location.push
props.history.push({ pathname: '/register', state: data_you_need_to_pass});
Example 3: this.props.history.location.push
<Link to={{ pathname: "/register", state: data_you_need_to_pass }}> Register</Link>
Example 4: props history
class Comp extends React.Component {
componentDidUpdate(prevProps) {
const locationChanged =
this.props.location !== prevProps.location;
const locationChanged =
this.props.history.location !== prevProps.history.location;
}
}
<Route component={Comp} />;
Example 5: props history
{
key: 'ac3df4',
pathname: '/somewhere',
search: '?some=search-string',
hash: '#howdy',
state: {
[userDefined]: true
}
}