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

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.

Vue.js is suitable for small and medium-sized projects and fast iterations, while React is suitable for large and complex applications. 1) Vue.js is easy to use and is suitable for situations where the team is insufficient or the project scale is small. 2) React has a richer ecosystem and is suitable for projects with high performance and complex functional needs.

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.

React combines JSX and HTML to improve user experience. 1) JSX embeds HTML to make development more intuitive. 2) The virtual DOM mechanism optimizes performance and reduces DOM operations. 3) Component-based management UI to improve maintainability. 4) State management and event processing enhance interactivity.

React is the preferred tool for building interactive front-end experiences. 1) React simplifies UI development through componentization and virtual DOM. 2) Components are divided into function components and class components. Function components are simpler and class components provide more life cycle methods. 3) The working principle of React relies on virtual DOM and reconciliation algorithm to improve performance. 4) State management uses useState or this.state, and life cycle methods such as componentDidMount are used for specific logic. 5) Basic usage includes creating components and managing state, and advanced usage involves custom hooks and performance optimization. 6) Common errors include improper status updates and performance issues, debugging skills include using ReactDevTools and Excellent

Netflixusesacustomframeworkcalled"Gibbon"builtonReact,notReactorVuedirectly.1)TeamExperience:Choosebasedonfamiliarity.2)ProjectComplexity:Vueforsimplerprojects,Reactforcomplexones.3)CustomizationNeeds:Reactoffersmoreflexibility.4)Ecosystema
