react-router Link 页面跳转(A->B)

1. props.parms

1.1 特点

  • 类似于GET表单提交,在url中能看到参数
  • 只能传字符串!

1.2 示例

1.2.1 配置路由

// 站点默认路由
<IndexRoute component={AppDownloadPage}/>
// 即将跳转到的路由(注意,多了两个参数!)
<Route path="helloWorld/:id/:name" component={HelloWorldPage}/>

1.2.2 Link超链接,准备跳转

<Link to={`/statics/helloWorld/${id}/${appName}`}>
// 或者
<Link to={{pathname: `/statics/helloWorld/${id}/${appName}`}}>

1.2.3 跳转完成,获取参数

const id = this.props.params.id;
const name = this.props.params.name;

2. query

2.1 特点

  • 类似于GET表单提交,在url中能看到参数
  • 可以传任何数据

2.2 示例

2.2.1 配置路由

// 站点默认路由
<IndexRoute component={AppDownloadPage}/>
// 即将跳转到的路由
<Route path="helloWorld" component={HelloWorldPage}/>

2.2.2 Link超链接,准备跳转

<Link to={{pathname: `/statics/helloWorld`, query: {id: id, name: appName}}}>

2.2.3 跳转完成,获取参数

const {id, name} = this.props.location.query;

3. state

3.1 特点

  • 类似于POST表单提交,在url中看不到参数
  • 可以传任何数据

3.2 示例

3.2.1 配置路由

// 站点默认路由
<IndexRoute component={AppDownloadPage}/>
// 即将跳转到的路由
<Route path="helloWorld" component={HelloWorldPage}/>

3.2.2 Link超链接,准备跳转

<Link to={{pathname: `/statics/helloWorld`, state: {id: id, name: appName}}}>

3.2.3 跳转完成,获取参数

const id = this.props.location.state.id;
const name = this.props.location.state.name;
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • Spring Cloud为开发人员提供了快速构建分布式系统中一些常见模式的工具(例如配置管理,服务发现,断路器,智...
    卡卡罗2017阅读 135,099评论 19 139
  • 22年12月更新:个人网站关停,如果仍旧对旧教程有兴趣参考 Github 的markdown内容[https://...
    tangyefei阅读 35,266评论 22 257
  • Lesson11、首先确保安装了Node.js和npm依赖包管理工具2、在git上克隆官方示例程序 git clo...
    冰_心阅读 2,743评论 0 16
  • Spring Boot 参考指南 介绍 转载自:https://www.gitbook.com/book/qbgb...
    毛宇鹏阅读 46,992评论 6 342
  • 坚持日记的第二天ヽ(•̀ω•́ )ゝ,感觉自己棒棒哒。 今天睡了个懒觉,感觉好舒服∩_∩。老妈说,鉴于...
    秦巴汉阅读 178评论 1 0