在react中使用Link带参数的路由跳转

2019-04-01  本文已影响0人  WEB小斗者

1,引入Link模块

 import { NavLink as Link } from 'react-router-dom'

2,Link标签中带上要传递的参数

<Link to={
        {
          pathname:`/要跳转的路径`,
          state:{key值:val值}
        }
      }>

3,在跳转页面接收传递的参数

componentWillMount(){
    //console.log(this.props.location)//传递过来的所有参数
    console.log(this.props.location.state.key值)//val值
}
上一篇 下一篇

猜你喜欢

热点阅读