如何使用this.props.history.push实现页面跳转并传递参数?

2026-06-09 10:211阅读0评论SEO资讯
  • 内容介绍
  • 文章标签
  • 相关推荐

本文共计209个文字,预计阅读时间需要1分钟。

如何使用this.props.history.push实现页面跳转并传递参数?

在React路由设置中,除了使用标签外,还可以使用`this.props.history.push`实现路由跳转和传递值:

第一种方式:在父组件中,设置路由标签:About第二种方式:在父组件中,直接设置:jsxthis.props.history.push('/about/:id')


react路由设置中,除了标签以外,还有一个this.props.history.push,设置落雨跳转和传值:

第一种方式:在父组件中,设置路由标签:

<Link to="/about/:id">About</Link>

第二种方式:在父组件中,设置点击事件:

<div onClick={this.click.bind(this)}>About</div>

//js
click(){
this.props.history.push({ pathname: "/about", state: { id } });
}

子组件中获取参数

如何使用this.props.history.push实现页面跳转并传递参数?

this.props.location.state.id


本文共计209个文字,预计阅读时间需要1分钟。

如何使用this.props.history.push实现页面跳转并传递参数?

在React路由设置中,除了使用标签外,还可以使用`this.props.history.push`实现路由跳转和传递值:

第一种方式:在父组件中,设置路由标签:About第二种方式:在父组件中,直接设置:jsxthis.props.history.push('/about/:id')


react路由设置中,除了标签以外,还有一个this.props.history.push,设置落雨跳转和传值:

第一种方式:在父组件中,设置路由标签:

<Link to="/about/:id">About</Link>

第二种方式:在父组件中,设置点击事件:

<div onClick={this.click.bind(this)}>About</div>

//js
click(){
this.props.history.push({ pathname: "/about", state: { id } });
}

子组件中获取参数

如何使用this.props.history.push实现页面跳转并传递参数?

this.props.location.state.id