升级router4.x之后,路由参数获取方式改变,之前3.x路由获取方式是:
this.props.location.query.id
就可以获得a标签等跳转后页面的参数。
但是,升级之后,location却没有了query这个属性

此外,4.x的参数分为了组件内参数和跳转参数,组件内参数是定义路由时给定的,使用this.props.match.params.name获取
<Route path="/path/:name" component={example} />
跳转获得的参数可以用 获得。this.props.location.search
是个字符串,可以使用queryString方法来获取指定参数

网友评论