美文网首页
在react中使用Link带参数的路由跳转

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

作者: WEB小斗者 | 来源:发表于2019-04-01 10:51 被阅读0次

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值
}

相关文章

网友评论

      本文标题:在react中使用Link带参数的路由跳转

      本文链接:https://www.haomeiwen.com/subject/hyvmbqtx.html