# react_day03 **Repository Path**: feng-yufan/react_day03 ## Basic Information - **Project Name**: react_day03 - **Description**: No description available - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2020-11-23 - **Last Updated**: 2020-12-19 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README 上午 ​ react的路由 ​ react需要安装react-router 和 react-router-dom ​ 然后需要引入HashRouter, Switch,Route, Link ​ 路由传值有4种 ### 1.params **`xxxthis.props.history.push({pathname:"/path/" + name});` `读取参数用:this.props.match.params.name` 优势 : 刷新地址栏,参数依然存在 缺点:只能传字符串,并且,如果传的值太多的话,url会变得长而丑陋。 ### 2.query **`this.props.history.push({pathname:"/query",query: { name : 'sunny' }});` `读取参数用: this.props.location.query.name` 优势:传参优雅,传递参数可传对象; 缺点:刷新地址栏,参数丢失 ### 3.state **` this.props.history.push({pathname:"/sort ",state : { name : 'sunny' }});` `读取参数用: this.props.location.query.state ` 优缺点同query ### 4.search **`xxxthis.props.history.push({pathname:"/web/departManange?tenantId" + row.tenantId});读取参数用: this.props.location.search` 路由跳转 this.props.history.push("/") 下午 ​ 嵌套路由是组件的一部分,那个组件需要嵌套,就写在哪, ​ 路由跳转不能用push ,要用 link 和to 跳转 ​