In react-router, the jump in the component can be used with <Link> But how to jump outside the component requires the use of react routing history The replace method is used in the same way as the push method. The function of replace is to replace the current history record. 1.hookimport {useHistory} from 'react-router-dom'; function goPage(e) { history.push({ pathname: "/home", state: {id: 1} }); } pathname is the routing address, state can be passed as a parameter Get parameters: import {useLocation} from 'react-router-dom'; function getParams(){ let location = useLocation(); let id = location.state.id; } 2. Class componentimport React from 'react'; import {createBrowserHistory} from "history"; class App extends React.Component { constructor(props) { super(props); } goPage() { let history = createBrowserHistory() history.push({ pathname: "/home", state: {id: 1} }); history.go(); } render() {return null;} } If history.go is not called, the route changes, but the page does not jump. This is the end of this article about how to use history jump in React Router. For more relevant React Router history jump content, please search for previous articles on 123WORDPRESS.COM or continue to browse the following related articles. I hope everyone will support 123WORDPRESS.COM in the future! You may also be interested in:
|
<<: Detailed explanation of Mybatis special character processing
>>: Solution to the inconsistency between crontab execution time and system time
Suddenly, I needed to build a private service for...
Preface The count function is used to count the r...
Basic structure: Copy code The code is as follows:...
The most important interactive design article in ...
Perform the following operations in the Ubuntu co...
Table of contents 1. Environment Configuration 1....
Usage of alter command in mysql to edit table str...
This article shares the specific code of React to...
Create a new project test1 on Code Cloud Enter th...
MySQL is the most popular relational database man...
Table of contents Import on demand: Global Import...
Preface I recently encountered this requirement a...
When processing batch updates of certain data, if...
1. Requirements When using the Vue.js framework t...
MySQL escape Escape means the original semantics ...