1.params
<Route path='/path/:name' component={Path}/>
<link to="/path/2">xxx</Link>
this.props.history.push({pathname:"/path/" + name});
讀取參數(shù)用:this.props.match.params.name
優(yōu)勢 : 刷新地址欄,參數(shù)依然存在
缺點:只能傳字符串抱究,并且恢氯,如果傳的值太多的話,url會變得長而丑陋鼓寺。
2.query
<Route path='/query' component={Query}/>
<Link to={{ path : ' /query' , query : { name : 'sunny' }}}>
this.props.history.push({pathname:"/query",query: { name : 'sunny' }});
讀取參數(shù)用: this.props.location.query.name
優(yōu)勢:傳參優(yōu)雅勋拟,傳遞參數(shù)可傳對象;
缺點:刷新地址欄妈候,參數(shù)丟失
3.state
<Route path='/sort ' component={Sort}/>
<Link to={{ path : ' /sort ' , state : { name : 'sunny' }}}>
this.props.history.push({pathname:"/sort ",state : { name : 'sunny' }});
讀取參數(shù)用: this.props.location.query.state
優(yōu)缺點同query
4.search
<Route path='/web/departManange ' component={DepartManange}/>
<link to="web/departManange?tenantId=12121212">xxx</Link>
this.props.history.push({pathname:"/web/departManange?tenantId" + row.tenantId});
讀取參數(shù)用: this.props.location.search
優(yōu)缺點同params