1.安装

react-router是核心库,在项目中不需要安装,web开发只需安装react-router-dom、native开发安装react-router-native。

2.url参数携带与获取

Url-regex-path

url

挂载组件获取url参数

/product/:id

/product/xxx

this.props.match.params.id

/article

/article?id=xxx

this.props.location.search

该属性的值为?id=1

 
this.props.history.push('/article',{id:5566})携带的数据在组件中通过this.props.location.state.id获取
 

3.Route组件的exact和strict

路由匹配的本质实际是拿window.loaction.pathname去与Route.path这个正则表达式做判断,也就是url中的问号不会影响匹配结果,因为url中的问号及后面的信息存储在window.location.pathname中

exact如果为true时,表示Route.path与location.pathname是相等关系(相等判断前先忽略Route.path结尾的/,忽略location.pathname结尾的一个反斜杠)

url-regex-path

url

是否匹配

/product或/product/

/product

/product/

/product?id=xxx

/product//

/product/xxx

 
 strict为true时,表示location.pathname包含Route.path中的内容就行,Route.path结尾的反斜杠将做为匹配依据。

url-regex-path

url

是否匹配

/product/

/product

/product/

/product//

/product/xxx

4.path通配符

/hello/:name
匹配 /hello/car
匹配 /hello/bus
 
/hello/:name?
匹配 /hello 
匹配 /hello/car 
匹配 /hello/bus 
 

react-router4的使用备注的更多相关文章

  1. [web前端] react router4.0 登录后返回之前浏览页面(回到来源页)

    本文链接:https://blog.csdn.net/zeroyulong/article/details/81911704困扰了好久的问题,最终还是在官方文档上找到了答案(看英文文档真心难受啊~~) ...

  2. [React] 10 - Tutorial: router

    Ref: REACT JS TUTORIAL #6 - React Router & Intro to Single Page Apps with React JS Ref: REACT JS ...

  3. 笔记react router 4(一)

    用过react router4.X的小伙伴一定知道,比起3.X的版本,router的使用上有了很大的改变. 首先,我们只需要安装 react-router-dom 即可使用.看到“dom”想必你就该知 ...

  4. 【共享单车】—— React后台管理系统开发手记:Router 4.0路由实战演练

    前言:以下内容基于React全家桶+AntD实战课程的学习实践过程记录.最终成果github地址:https://github.com/66Web/react-antd-manager,欢迎star. ...

  5. react link引入外部css样式的坑

    刚开始的代码是这样的,使用react router4.x写的demo路由跳转后,页面的没有渲染,是因为没有引入外部css文件(或者说引入外部文件路径错误) <!DOCTYPE html> ...

  6. react 开发过程中的总结/归纳

    1.点击元素,获取绑定该事件的父级元素,使用 e.currentTarget.e.target 获取的是,出发该事件的元素,该元素有可能是所绑定事件的元素的子元素. 2.使用 react router ...

  7. 利用 React 高阶组件实现一个面包屑导航

    什么是 React 高阶组件 React 高阶组件就是以高阶函数的方式包裹需要修饰的 React 组件,并返回处理完成后的 React 组件.React 高阶组件在 React 生态中使用的非常频繁, ...

  8. react、react-router、redux 也许是最佳小实践1

    小前言 这是一个小小的有关react的小例子,希望通过一个小例子,可以让新手更好的了解到react.react-router4.0.redux的集中使用方法. 这是基于create-react-app ...

  9. React:redux+router4搭建应用骨架

    可能是短期内关于react的对后一篇笔记.假设读者对redux和router4有基本了解. 缘由: 现在网上很多关于react+redux的文章都是沿用传统的文件组织形式,即: |--componen ...

  10. 【腾讯Bugly干货分享】React Native项目实战总结

    本文来自于腾讯bugly开发者社区,非经作者同意,请勿转载,原文地址:http://dev.qq.com/topic/577e16a7640ad7b4682c64a7 “8小时内拼工作,8小时外拼成长 ...

随机推荐

  1. 前端知识点回顾之重点篇——CSS中flex布局

    flex布局 来源: http://www.ruanyifeng.com/blog/2015/07/flex-grammar.html?utm_source=tuicool 采用 Flex 布局的元素 ...

  2. quartus仿真提示: Can't launch the ModelSim-Altera software

    quartus仿真提示: Can't launch the ModelSim-Altera software 2017年07月13日 17:54:50 小怪_tan 阅读数:3255   路径中的结尾 ...

  3. Sketch2Code - Transform sketches into HTML using AI

    Sketch2Code - Transform sketches into HTML using AI https://sketch2code.azurewebsites.net/generated- ...

  4. (转)Ngx_Lua使用分享

    原文:https://www.cnblogs.com/yanzi-meng/p/9450999.html ngx_lua 模块详细讲解(基于openresty)---https://www.cnblo ...

  5. wms证书配置操作

      1. 在应用的/home下 把证书cp到/usr/local/apache2/conf 2. 打开文件/usr/local/apache2/conf/extra/httpd-ssl.conf,找到 ...

  6. python初级(302) 6 对象(五)

    一.复习 1.什么是多态 2.什么是继承 二.继承:向父母学习 在面向对象编程中,类可以从其他类继承属性和方法.这样就有了类的整个家族,这个家族中的每个类共享相同的属性和方法.这样一来,每次向家族增加 ...

  7. Promise.resolve解析

    总结自:https://blog.csdn.net/lq15310444798/article/details/81275278 Promise.resolve返回一个Promise实例 参数分4种情 ...

  8. Centos7——无法访问Windows系统的分区

    我的Windows分区是Ntfs格式的,所以我直接安装ntfs即可解决年 yum -y install ntfs*

  9. Jenkins - 分布式构建

    1 - 简介 Jenkins支持分布式多节点(Master-Slave)运行模式. 将安装Jenkins的主机作为Master节点,然后通过界面配置(或远端启动服务)来添加Slave节点. 在这种部署 ...

  10. 在Django中显示操作数据库的语句

    需要在配置中加上这个 LOGGING = { 'version':1, 'disable_existing_loggers':False, 'handlers':{ 'console':{ 'leve ...