君陌离的博客

vuePress-theme-reco 君陌离    2018 - 2020
君陌离的博客 君陌离的博客

Choose mode

  • dark
  • auto
  • light
首页
我的作品
  • 项目橱窗
  • blog模板
分类
  • 数据库
  • CSS
  • 摘记
  • JS
  • Node
  • Vue
  • React
  • GIT
  • Promise
  • Liunx
  • Xshell
  • ajax
  • WINDOWS
  • Python
  • 随笔
  • 脚手架
  • node
  • 自动化
标签
笔记
时间线
About Me
  • 关于我
  • 赞赏
Contact
  • GitHub
  • QQ
author-avatar

君陌离

70

文章

90

标签

首页
我的作品
  • 项目橱窗
  • blog模板
分类
  • 数据库
  • CSS
  • 摘记
  • JS
  • Node
  • Vue
  • React
  • GIT
  • Promise
  • Liunx
  • Xshell
  • ajax
  • WINDOWS
  • Python
  • 随笔
  • 脚手架
  • node
  • 自动化
标签
笔记
时间线
About Me
  • 关于我
  • 赞赏
Contact
  • GitHub
  • QQ
  • HTML5

  • JS

  • 微信小程序

  • 数据库

  • React

    • 与Vue相比React的指令使用方法
    • React采坑记录
    • react路由跳转、传参3中方式及区别
    • React生命周期执行顺序
  • Vue

  • vuepress

react路由跳转、传参3中方式及区别

vuePress-theme-reco 君陌离    2018 - 2020

react路由跳转、传参3中方式及区别

君陌离 2020-08-12 14:44:26 React路由跳转路由传参

# 1.路由表配置:参数地址栏显示

  • Route:
<Route path="/list/:id" component={List} />
1
  • html:
<Link to='/list/2' >跳转列表页面</Link>
1
  • Js页面接收:
this.props.history.push('/list/2');
console.log(this.props.match.params.id)//传递过来的所有参数
1
2

# 2.query方法:参数地址栏不显示,刷新地址栏,参数丢失

  • html:
<Link to={{ pathname: '/list', query: { name: 'xlf' } }}>跳转列表页面</Link>
1
  • Js方式:
this.props.history.push({ pathname: '/list', query: { name: ' sunny' } })
1
  • Js页面接收:
console.log(this.props.location.query.name)//传递过来的所有参数
1

# 3.state方法:参数地址栏不显示,刷新地址栏,参数不丢失,但是该方法只支持BrowerRouter,不支持HashRouter

  • Html:
<Link to={{ pathname: '/list', state: { name: 'xlf' } }}>跳转列表页面</Link>
1
  • js:
this.props.history.push({ pathname: '/list', state: { name: 'sunny' } })
1
  • Js页面接收
console.log(this.props.location.state.name)//传递过来的所有参数
1
欢迎来到 您的站点名称($site.title)
看板娘