react跳转传值如何实现

发布时间:2023-01-13 13:44:48 作者:iii
来源:亿速云 阅读:127

本篇内容主要讲解“react跳转传值如何实现”,感兴趣的朋友不妨来看看。本文介绍的方法操作简单快捷,实用性强。下面就让小编来带大家学习“react跳转传值如何实现”吧!

react跳转传值的实现方法:1、通过“history.push”或“NavLink”实现页面跳转;2、通过“this.props.history.push({pathname: 'login',query: {id: ...,name: ...}})this.props.history.push('modify')”实现传值即可。

react项目页面跳转/传值

一、跳转

1、history.push 跳转
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/params
this.props.history.push({
   pathname: 'login',
   query: {
       id: 3231,
       name: 3231
   }})this.props.history.push('modify')
2、路由传值获取参数
this.props.match.query.id // 3231
this.props.match.params.name // 3231
react跳转传值如何实现
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跳转传值如何实现”有了更深的了解,不妨来实际操作一番吧!这里是亿速云网站,更多相关内容可以进入相关频道进行查询,关注我们,继续学习!

推荐阅读:
  1. 界面的跳转和传值
  2. 使用react怎么实现组件传值

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

react

上一篇:CSS中nth-child与nth-of-type的元素怎么使用

下一篇:react如何实现表头固定

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》