Home  >  Article  >  Web Front-end  >  How to achieve page jump without recording in react

How to achieve page jump without recording in react

藏色散人
藏色散人Original
2022-12-30 10:07:282580browse

React method to realize page jump without recording: 1. Open the corresponding react file; 2. Use the "this.props.history.replace("/home");" method to realize page jump and clear it Just the history of the current page.

How to achieve page jump without recording in react

The operating environment of this tutorial: Windows 10 system, react18.0.0 version, Dell G3 computer.

How to achieve page jump without recording in react?

React-router: Page jump and clear the history of the current page

There are the following situations:

The user opens the activation link; after the user completes the activation process, It will be moved to another page.

I don't want to keep the activation link in the browser's history because when the user returns, they will enter the activation step again.

You can jump to the page through replace

this.props.history.replace("/home");

Related introduction:

this.props.history.replace()The parameter in this method is the Link whose replace attribute is true The to attribute of the component can also pass state;

 this.props.history.replace(`/Page2/Div1`)
 //等同于
 <Link replace to=`/Page2/Div1`></Link>
 this.props.history.replace(`/Page2/Div1`,{ id: 1, message: "你好啊" })
 //等同于
 <Link replace to={{pathname:`/Page2/Div1`,state:{id: 1, message: "你好啊"}}></Link>

Recommended learning: "react video tutorial"

The above is the detailed content of How to achieve page jump without recording 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