no message
This commit is contained in:
@@ -20,4 +20,6 @@
|
||||
12、路由嵌套
|
||||
13、路由传参 pathname
|
||||
14、push与replace
|
||||
15、witchRoute 使一般组件拥有路由组件的属性,返回值是一个新组件
|
||||
15、witchRoute 使一般组件拥有路由组件的属性,返回值是一个新组件
|
||||
16、编程式路由
|
||||
|
||||
@@ -8,7 +8,7 @@ import queryString from 'query-string';
|
||||
import React,{Component} from 'react'
|
||||
class Car extends Component{
|
||||
render(){
|
||||
let {search}=this.props.location
|
||||
let {search}=this.props.location // search参数
|
||||
const {name,id}=queryString.parse(search)
|
||||
return (
|
||||
<div>
|
||||
|
||||
@@ -7,8 +7,8 @@
|
||||
import React,{Component} from 'react'
|
||||
class New extends Component{
|
||||
render(){
|
||||
const {name,id}=this.props.match.params
|
||||
console.log(this.props.match.params)
|
||||
const {name,id}=this.props.match.params // params参数
|
||||
console.log(this.props.match.params)
|
||||
return(
|
||||
<div>
|
||||
<h2>this is New</h2>
|
||||
|
||||
@@ -16,6 +16,18 @@ class Header extends Component{
|
||||
go=()=>{
|
||||
this.props.history.go(-2)
|
||||
}
|
||||
push1=()=>{
|
||||
this.props.history.push('/home/news/chenxuan/123')
|
||||
}
|
||||
push2=()=>{
|
||||
this.props.history.push('/home/car?name=chenxuan&id=123456')
|
||||
}
|
||||
replace1=()=>{
|
||||
this.props.history.replace('/home/money')
|
||||
}
|
||||
replace2=()=>{
|
||||
this.props.history.replace('/home/money',{name:"陈轩",age:"18岁",sex:"男"})
|
||||
}
|
||||
render(){
|
||||
return(
|
||||
<div className="header">
|
||||
@@ -23,6 +35,10 @@ class Header extends Component{
|
||||
<button onClick={this.back}>前进</button>
|
||||
<button onClick={this.forward}>后退</button>
|
||||
<button onClick={this.go}>后退2步骤</button>
|
||||
<button onClick={this.push1}>push1-params</button>
|
||||
<button onClick={this.push2}>push2-search</button>
|
||||
<button onClick={this.replace1}>replace1</button>
|
||||
<button onClick={this.replace2}>replace2-state</button>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
@@ -20,7 +20,7 @@ class Home extends Component{
|
||||
<Link replace={true} to={{pathname:'/home/money',state:{name:"陈轩",age:"18岁",sex:"男"}}} children="财经" />
|
||||
</ul>
|
||||
<div className='homeContent'>
|
||||
<Route path="/home/news/:name/:id" component={New} />
|
||||
<Route path="/home/news/:name/:id" component={New} />
|
||||
<Route path="/home/car" component={Car} />
|
||||
<Route path="/home/money" component={Money} />
|
||||
<Redirect to="/home/car" />
|
||||
|
||||
Reference in New Issue
Block a user