1. Link's to attribute (1) Place the routing path 2. Link's replace attributeAdd replace to replace the previous page before the jump with the current page, and only push the current page into the stack 3. Link parameter transfer Add "/key value" after the to path Code example:import React,{Component} from 'react' //import {Route,BrowserRouter,Link} from 'react-router-dom' //Rename BrowserRouter to Router import { BrowserRouter as Router, Link, Route } from 'react-router-dom' import { Button } from 'antd'; import './App.css'; function Home() { return( <div>admin homepage</div> ) } function Me(props) { console.log(props) return( <div>admin my</div> ) } function Product(props) { return( <div>admin product page:{props.match.params.id}</div> ) } export default class App extends Component { constructor() { super(); } render() { {/*If the path is written in object form and is the same as below, pathname, search, and hash will be automatically concatenated on the url path, and state is the data passed into the component*/} let obj={pathname:"/me",search:'?username=admin',hash:"#abc",state:{msg:'hello'}} return( <div id='app'> {/*You can put multiple BrowserRouter*/} <Router> {/*Because the component also returns HTML content, you can directly return HTML content through the function to act as a component, but you cannot directly write HTML content*/} <div> <Route path="/" exact component={()=><div>首页</div>}></Route> <Route path="/product" component={()=><div>product</div>}></Route> <Route path="/me" component={()=><div>me</div>}></Route> </div> {/*<Route path="/" component={function(){return <div>首页2</div>}}></Route>*/} </Router> {/*There can only be one root container inside BrowserRouter to wrap other content*/} {/*After adding basename='/xx', when you click Link to jump to other routes, the url will add /xx to the front of the route name, so both the route path and the route path with admin added can match the route*/} <Router basename='/admin'> <div> <div className='nav'> <Link to='/'>Home</Link> <Link to='/product/123'>Product</Link> {/*You can output props in the corresponding component to view the information of the passed object, add replace to replace the previous page before the jump with the current page, and only push the current page into the stack*/} <Link to={obj} replace>Personal Center</Link> </div> <Route path="/" exact component={Home}></Route> <Route path="/product/:id" component={Product}></Route> <Route path="/me" exact component={Me}></Route> </div> </Router> </div> ) } } This is the end of this article about the detailed configuration of react routing Link. For more relevant react routing Link 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:
|
<<: Introduction to keyword design methods in web design
>>: Summary of basic operations for MySQL beginners
Since I need to learn how to build servers and da...
The effect is very simple, just copy the following...
Table of contents Preface How to switch between m...
Source: http://www.ruoyi.vip/ import Vue from ...
Founder Type Library is a font library developed ...
Table of contents Preface Connection Management A...
Table of contents Solution 1 Solution 2 When crea...
1. Indexing principle Indexes are used to quickly...
Preface In the process of developing a mini progr...
This is because the database server is set to aut...
Table of contents 1: Single machine password-free...
Last time, a very studious fan asked if it was po...
Table of contents Set is a special collection who...
The Truncate table statement is used to delete/tr...
How to center an element in the browser window He...