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
Today, when I was writing a small program, I used...
Last time, we came up with two header layouts, on...
Solution 1: Use conditional import in HTML docume...
Learning objectives: The two functions parseInt()...
Table of contents Preface text 1. Install styleli...
Table of contents Object parameters using destruc...
introduction As usual, let's start with a sce...
The commonly used Oracle10g partitions are: range...
CSS writing order 1. Position attributes (positio...
MySQL error: Parameter index out of range (1 >...
I've been using redis recently and I find it ...
In the previous blog, we talked about using Nginx...
Table of contents Preface What is VirtualDOM? Rea...
Vue recommends using templates to create your HTM...