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
Table of contents Safe Mode Settings test 1. Upda...
Table of contents 1 Question 2 Methods 3 Experime...
<br />When inserting music into a web page, ...
What is Nginx access restriction configuration Ng...
Table of contents The cause of the incident Anato...
Note 1: The entire background in the above pictur...
Use CSS filter to write mouse over effect <div...
The overall architecture of MySQL is divided into...
In a recent project, I wanted to align text verti...
Load one or more features <template> <di...
People who use virtual machines usually set up sh...
Table of contents 1. Insert the queried results 2...
1. Introduction By enabling the slow query log, M...
Table of contents Directory Structure bin directo...
Table of contents 1. Element offset series 2. Ele...