加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

React 路由传参

发布时间:2020-12-15 20:36:41 所属栏目:百科 来源:网络整理
导读:方式 一: 通过params 1.路由表中 2.Link处 HTML方式 XXXX JS方式 this.props.history.push( ‘/sort/‘+‘2‘ ) 3.sort页面 通过 this.props.metch.params.id 就可以接受到传递过来的参数(id) 方式 二: 通过query 前提:必须由其他页面跳过来,参数才会
方式 一: 通过params 1.路由表中             2.Link处 HTML方式 XXXX                  JS方式 this.props.history.push( ‘/sort/‘+‘2‘ )             3.sort页面 通过 this.props.metch.params.id 就可以接受到传递过来的参数(id)             方式 二: 通过query 前提:必须由其他页面跳过来,参数才会被传递过来     注:不需要配置路由表。路由表中的内容照常: 1.Link处 HTML方式            JS方式 this.props.history.push({ path : ‘/sort‘,query : { name: ‘ sunny‘} }) 2.sort页面 this.props.location.query.name 方式 三: 通过state 同query差不多,只是属性不一样,而且state传的参数是加密的,query传的参数是公开的,在地址栏 1.Link 处 HTML方式:    JS方式: this.props.history.push({ pathname:‘/sort‘,state:{name : ‘sunny‘ } })    2.sort页面 this.props.location.state.name

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读