1 路由動(dòng)態(tài)參數(shù)
路由定義
<Route path="/component/:id" component={Component} />
Link定義
<Link to="/component/10">toComponent</Link>
Component 組件中接收參數(shù)
this.props.match.params.id // id == 10
2 Link組件 to:String
路由定義(一般定義規(guī)則)
<Route path="/" component={Component} />
Link定義
<Link to="/?sort=name">Zillow Group</Link>
Component 組件中接收參數(shù)
this.props.location.search // search == "?sort=name"
3 Link組件 to:Object
路由定義(一般定義規(guī)則)
<Route path="/component" component={Component} />
Link定義
let obj = {
pathname: '/component',
search: '?sort=name',
query: { fromDashboard: 123 },
state: { fromDashboard: 123 }
}
<Link to="{obj}">Zillow Group</Link>
Component 組件中接收參數(shù)
this.props.location.search // search == "?sort=name"
this.props.location.query // query == { fromDashboard: 123 }
this.props.location.state // state == { fromDashboard: 123 }
注意:
1 query 在頁(yè)面刷新后 會(huì)消失
2 query 和 state都是隱式傳遞