Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the different between browserHistory.push() and location.replace()

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>
    );
}
like image 397
ip192 Avatar asked Oct 24 '16 04:10

ip192


1 Answers

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 ;)

like image 86
Timo Reymann Avatar answered Jan 01 '23 00:01

Timo Reymann