What are react routes
React routing includes: 1. Page routing, code such as "window.location.href='...'history.back()"; 2. h5 routing, code such as "window.onchange = function ( ) {console.log(window.location.hash)}"; 3. Hash routing, code such as "history.pushState(...)".
The operating environment of this tutorial: Windows 10 system, react18.0.0 version, Dell G3 computer.
What are the react routes?
Routing in React
1. Three common routes
(1) Page routing
window.location.href='https://www.hao123.com/' history.back()Copy after login
(2) h5 routing
window.location = '#hash' window.onchange = function () { console.log(window.location.hash) }Copy after login
(3) hash routing
//推进一个状态 history.pushState('name','title','/path') //替换一个状态 history.replaceState('name','title','/path')Copy after login
2. React-Router Routing introduction
1. Routing method
2. Routing rules
3. Reason option
For example: /path and path/list, path/list will match /path in order, which cannot achieve the desired effect. Add the exact keyword to achieve a complete match, which must be exactly the same. to match.
4. Jump navigation, equivalent to a tag
: Jump page
5. Automatic jump
3. Use of React-Router
1. Import package
yarn add react-router-dom
import {BrowserRouter, Route, Link} from "react-router-dom";
2. BrowserRouter package
<browserrouter> <div> <route></route> <route></route> </div> </browserrouter>
- component is used to modify the routing page to be jumped. The page content is: Home and Detail are two real components
- path: Matching routing rules
- exact: Modify the matching effect, adding it means exact matching, not adding it means fuzzy matching, for example:
- path={'/'} means matching: http:/ /localhost:3000/, if it is http://localhost:3000/99, it will not match
- path={'/detail/'} means matching: http://localhost:3000/detail/xxxxxxx , the latter is not limited, it will be OK if the previous match is successful
3. Passing value of route
http://localhost:3000/detail
(1) Routing parameter value passing
Routing parameters
Jump parameters:
Receive parameters:
this.props.match.params.id
Print result
3. Directly use
Access results
http://localhost:3000/detail/3
(2) Routing parameter value passing
Routing parameters
Jump parameters:
Receive parameters:
this.props.location.search
Print results
?id=3. Need to parse by yourself
Access result
http://localhost:3000/detail?id=3
4. Jump principle
The to parameter of Link matches the path parameter in Route, then the jump is executed and jumps to the component set in the component in Route.
A picture from the online summary describes it well:
Recommended learning: "react video tutorial"
The above is the detailed content of What are react routes. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



ReactRouter User Guide: How to Implement Front-End Routing Control With the popularity of single-page applications, front-end routing has become an important part that cannot be ignored. As the most popular routing library in the React ecosystem, ReactRouter provides rich functions and easy-to-use APIs, making the implementation of front-end routing very simple and flexible. This article will introduce how to use ReactRouter and provide some specific code examples. To install ReactRouter first, we need

PHP, Vue and React: How to choose the most suitable front-end framework? With the continuous development of Internet technology, front-end frameworks play a vital role in Web development. PHP, Vue and React are three representative front-end frameworks, each with its own unique characteristics and advantages. When choosing which front-end framework to use, developers need to make an informed decision based on project needs, team skills, and personal preferences. This article will compare the characteristics and uses of the three front-end frameworks PHP, Vue and React.

Apache Camel is an Enterprise Service Bus (ESB)-based integration framework that can easily integrate disparate applications, services, and data sources to automate complex business processes. ApacheCamel uses route-based configuration to easily define and manage integration processes. Key features of ApacheCamel include: Flexibility: ApacheCamel can be easily integrated with a variety of applications, services, and data sources. It supports multiple protocols, including HTTP, JMS, SOAP, FTP, etc. Efficiency: ApacheCamel is very efficient, it can handle a large number of messages. It uses an asynchronous messaging mechanism, which improves performance. Expandable

Integration of Java framework and React framework: Steps: Set up the back-end Java framework. Create project structure. Configure build tools. Create React applications. Write REST API endpoints. Configure the communication mechanism. Practical case (SpringBoot+React): Java code: Define RESTfulAPI controller. React code: Get and display the data returned by the API.

In modern web applications, implementing web page navigation and routing is a very important part. Using JavaScript functions to implement this function can make our web applications more flexible, scalable and user-friendly. This article will introduce how to use JavaScript functions to implement web page navigation and routing, and provide specific code examples. Implementing web page navigation For a web application, web page navigation is the most frequently operated part by users. When a user clicks on the page

Implementation method and experience summary of flexible configuration of routing rules in PHP Introduction: In Web development, routing rules are a very important part, which determines the corresponding relationship between URL and specific PHP scripts. In the traditional development method, we usually configure various URL rules in the routing file, and then map the URL to the corresponding script path. However, as the complexity of the project increases and business requirements change, it will become very cumbersome and inflexible if each URL needs to be configured manually. So, how to implement in PHP

Uniapp is a cross-end framework based on Vue.js. It supports one-time writing and generates multi-end applications such as H5, mini programs, and APPs at the same time. It pays great attention to performance and development efficiency during the development process. In Uniapp, the dynamic addition and deletion of routes is a problem that is often encountered during the development process. Therefore, this article will introduce the dynamic addition and deletion of routes in Uniapp and provide specific code examples. 1. Dynamic addition of routes Dynamic addition of routes can be done according to actual needs when the page is loaded or after user operation.

In Golang, using functions to handle web request routing is an extensible and modular method of building APIs. It involves the following steps: Install the HTTP router library. Create a router. Define path patterns and handler functions for routes. Write handler functions to handle requests and return responses. Run the router using an HTTP server. This process allows for a modular approach when handling incoming requests, improving reusability, maintainability, and testability.
