Home >Web Front-end >JS Tutorial >What is the difference between push and replace in react

What is the difference between push and replace in react

青灯夜游
青灯夜游Original
2020-12-23 16:46:076629browse

The difference between push and replace in react: push jump will form a history and can return to the previous layer; replace jump will not form a history and cannot return to the previous layer. It is applicable after login. Need to go back to the login page.

What is the difference between push and replace in react

The operating environment of this tutorial: windows7 system, react16 version, Dell G3 computer.

The difference between push and replace in react

push: a-b-c, you can return to the previous level

push jump A history will be formed and you can return to the previous layer.

Syntax:

this.props.history.push('router地址')

replace: a-b-c cannot return to the previous level. It is applicable after logging in and there is no need to return to the login page

replace jump will not form a history and cannot return to the previous level.

Grammar:

this.props.history.replace('router地址')

For more programming-related knowledge, please visit: Programming Teaching! !

Related tutorial recommendations: React video tutorial

The above is the detailed content of What is the difference between push and replace in react. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn