您好,欢迎访问一九零五行业门户网

react跳转传值怎么实现

react跳转传值的实现方法:1、通过“history.push”或“navlink”实现页面跳转;2、通过“this.props.history.push({pathname: 'login',query: {id: ...,name: ...}})this.props.history.push('modify')”实现传值即可。
本教程操作环境:windows10系统、react18.0.0版、dell g3电脑。
react跳转传值怎么实现?
react项目页面跳转/传值
一、跳转1、history.push 跳转引用 withrouter导出组件时使用import { withrouter } from 'react-router-dom';class header extends react.component {}export default withrouter(header);
2、navlink跳转import { navlink } from "react-router-dom";<navlink to="/modify">修改密码</navlink>
二、传值1、路由传值 query/paramsthis.props.history.push({ pathname: 'login', query: { id: 3231, name: 3231 }})this.props.history.push('modify')
2、路由传值获取参数this.props.match.query.id // 3231this.props.match.params.name // 3231
3、props传值父组件:
state = { collapsed: false,};render() { const { collapsed } = this.state; return ( <slider collapsed={collapsed}/> )}
子组件:
componentdidmount(){ // console.log(this.props) const { pathname } = this.props.location if( pathname ) { this.setstate({ selectedkeys:this.props.location.pathname }) }}
console.log(this.props)
推荐学习:《react视频教程》
以上就是react跳转传值怎么实现的详细内容。
其它类似信息

推荐信息