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项目页面跳转/传值
- 引用 withRouter
- 导出组件时使用
import { withRouter } from 'react-router-dom';
class Header extends React.Component {
}
export default withRouter(Header);import { NavLink } from "react-router-dom";
<NavLink to="/modify">修改密码</NavLink>this.props.history.push({
pathname: 'login',
query: {
id: 3231,
name: 3231
}})this.props.history.push('modify')this.props.match.query.id // 3231 this.props.match.params.name // 3231

父组件:
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跳转传值怎么实现的详细内容,更多请关注php中文网其它相关文章!
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号