React router 4 獲取路由引數,跨頁面引數

看風景就發表於2018-10-10
1. match通過路徑
<Route path="/path/:name" component={example} />
路由元件內獲取引數使用
this.props.match.params.name
2. query String 通過search
//mirrorx中使用push的引數search,link中使用與此類似
actions.routing.push({
  pathname: '/path/example',
  search: `?name=${name}`,
 }
)
路由元件內獲取引數使用
this.props.location.search
是個字串,可以使用querySrirng方法來獲取指定引數
原來this.props.location.query.name這種方式在v4版本中不再可用,老版本獲取引數方式

相關文章