I build my project with react, when I want to change the URL I find both browserHistory.push(myUrl) and location.replace() are worked. So I want to know what's the different between them.
divClick() {
location.replace('/doctor/task');
// browserHistory.push('/doctor/task');
}
render() {
return (
<div>
<div onClick={this.divClick.bind(this)}>Change</div>
</div>
);
}
History Push The user can go forward and backward in the browser and the url will change. It works like a programmatic link with no affect on current url.
Location Replace The link of the page is set to the new one, but the user can't go between the replaced.
Hope this will help you ;)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With