1、params传参(刷新页面后参数不消失,参数会在地址栏显示)
路由页面:<Route path="/link/:id" component={Demo}><Route>
链接方式:<link to={'/link/'+'xxx'}>首页</link>或<Link to={{pathname:'/link/'+'xxx'}}>首页</link>
js方式:this.props.history.push('/link/'+'xxx')或this.props.history.push({pathname:'/link/'+'xxx'})
获取参数:this.props.match.params.id
2、query传参(刷新页面后参数消失)
路由页面:<Route path="/demo" component={Demo}><Route>
链接方式:<Link to={{pathname:'/link',query:{id:2,name:'lucy'}}}>xxx</Link>
js方式:this.props.history.push({pathname:'/dmeo',query:{id:2,name:'lucy'}})
获取参数:this.props.location.query.name
3、state传参(刷新页面后参数不消失,state传的参数是加密的)
路由页面:<Route path="/link" component={Demo}><Route>
链接方式:<Link to={{pathname:'/link',state:{id:2,name:'lucy'}}}>xxx</Link>
js方式:this.props.history.push({pathname:'/dmeo',state:{id:2,name:'lucy'}})
获取参数:this.props.location.state.name
|