path通配符:

<Route path="/hello/:name">
// 匹配 /hello/michael
// 匹配 /hello/ryan <Route path="/hello(/:name)">
// 匹配 /hello
// 匹配 /hello/michael
// 匹配 /hello/ryan <Route path="/files/*.*">
// 匹配 /files/hello.jpg
// 匹配 /files/hello.html <Route path="/files/*">
// 匹配 /files/
// 匹配 /files/a
// 匹配 /files/a/b <Route path="/**/*.jpg">
// 匹配 /files/hello.jpg
// 匹配 /files/path/to/file.jpg router路由的匹配规则为从上到下,如果有两个相同的路由,会匹配第一个,第二个无效。 router常用组件如下: Link Link组件用于取代<a>元素,生成一个链接,允许用户点击后跳转到另一个路由。它基本上就是<a>元素的React 版本,可以接收Router的状态。 render(){
  return (
    <ul>
      <li><Link to="/haha">哈哈</Link></li>
    </ul>
  )
} 增加样式
<Link to="/haha" activeStyle={{ color: #f00 }}></Link> 增加class
<Link to="/haha" activeclassName></Link>

IndexRoute
<Router>
  <Route dath="/" component={App}>     
<Route dath="about" component={About}></Route>
    <Route dath="con" component={Con}></Route>
  </Route>
</Router> 访问根路由“/”时,不会加载任何子组件,<IndexRoute component={Home}></IndexRoute>,这样,访问根路径时会直接加载Home组件,相当于给根路由默认指定了一个组件来加载
注意:IndexRoute组件没有路径参数dath. IndexLink 加载根路由'/'时,activeclassName和activeStyle会失效,或者说总是生效,因为它会匹配根路由下的所有子路由,而IndexLink会使用路由的精确匹配,不会出错
<IndexLink activeStyle={{color: '#f00'}} activeclassName="font"></IndexLink> Redirect 从当前路由跳转到另一个路由
<Redirect from="/a" to="/b"></Redirect> 从"/a"跳转到"/b" IndexRedirect 访问根路由"/"时,将路径指向某个特定的子路由。
<Rouder>
  <Roude dath="/" component={App}>
    <IndexRedirect to="/about"></IndexRedirect>
    <Route dath="/about" component={About}></Route>
  </Roude>
</Rouder> history history属性用来监听地址栏的变化,一般分为3种
  1. hashHistory
  2. browserHistory
  3. createMemoryHistory

hashHistory: <Router history={hashHistory} routes={routes}> 通过路由的hash部分切换 #

browserHistory: <Router history={browserHistory} routes={routes}></Router> 显示正常的路径,背后调用的是浏览器的History API,但是这种情况需要对服务器进行改造,否则用户直接向服务器请求某个子路由,会导致找不到网页的404错误,

如果开发服务器使用的是webpack-dev-server,加上--history-api-fallback参数就可以了。

$ webpack-dev-server --inline--content-base . --history-api-fallback

createMemoryHistory: 主要用于服务器渲染,不与浏览器url互动    const history=createMemoryHistory(location)

表单处理

<form>

  <input type="text" placeholder="name" />

  <input type="password" placeholder="password" />

</form>

 


[react-router] 平时积累的更多相关文章

  1. React native 平时积累笔记

    常用插件: react-native-check-box 复选框react-native-sortable-listview 列表拖拽排序 react-native-doc-viewer 预览组件 r ...

  2. [Redux] Filtering Redux State with React Router Params

    We will learn how adding React Router shifts the balance of responsibilities, and how the components ...

  3. [转] React Router 使用教程

    PS:react-route就是一个决定生成什么父子关系的组件,一般和layout结合起来,保证layout不行,内部的子html进行跳转 你会发现,它不是一个库,也不是一个框架,而是一个庞大的体系. ...

  4. [Redux] Navigating with React Router <Link>

    We will learn how to change the address bar using a component from React Router. In Root.js: We need ...

  5. [Redux] Adding React Router to the Project

    We will learn how to add React Router to a Redux project and make it render our root component. Inst ...

  6. React Router基础使用

    React是个技术栈,单单使用React很难构建复杂的Web应用程序,很多情况下我们需要引入其他相关的技术 React Router是React的路由库,保持相关页面部件与URL间的同步 下面就来简单 ...

  7. 最新的chart 聊天功能( webpack2 + react + router + redux + scss + nodejs + express + mysql + es6/7)

    请表明转载链接: 我是一个喜欢捣腾的人,没事总喜欢学点新东西,可能现在用不到,但是不保证下一刻用不到. 我一直从事的是依赖angular.js 的web开发,但是我怎么能一直用它呢?看看最近火的一塌糊 ...

  8. react router 4.0以上的路由应用

    thead>tr>th{padding:8px;line-height:1.4285714;border-top:1px solid #ddd}.table>thead>tr& ...

  9. React Router 使用教程

    一.基本用法 React Router 安装命令如下. $ npm install -S react-router 使用时,路由器Router就是React的一个组件. import { Router ...

  10. 关于react router 4 的小实践

    详细代码栗子:https://github.com/wayaha/react-dom-CY clone然后 npm install npm start 分割线 1.这个项目使用create-react ...

随机推荐

  1. RabbitMQ学习(二):Java使用RabbitMQ要点知识

    转  https://blog.csdn.net/leixiaotao_java/article/details/78924863 1.maven依赖 <dependency> <g ...

  2. PHPExcel探索之旅

    学习地址: https://www.imooc.com/video/8359 下载地址: https://packagist.org/packages/phpoffice/phpexcel 用comp ...

  3. Applied Nonparametric Statistics-lec2

    Ref: https://onlinecourses.science.psu.edu/stat464/print/book/export/html/3 The Binomial Distributio ...

  4. solr7.7.1完整教程

    安装 上传solr-7.7.1.tgz至服务器 opt文件加下 解压 tar -zxvf solr-7.7.1.tgz 运行 进入到加压后的文件夹/opt/solr-7.7.1,执行一下命令启动sol ...

  5. Tourists Gym - 101002I LCA——dfs+RMQ在线算法

    LCA(Least Common Ancestors),即最近公共祖先,是指这样一个问题:在有根树中,找出某两个结点u和v最近的公共祖先(另一种说法,离树根最远的公共祖先). 知识需求:1)RMQ的S ...

  6. HDU - 1251 统计难题(Trie树)

    有很多单词(只有小写字母组成,不会有重复的单词出现) 要统计出以某个字符串为前缀的单词数量(单词本身也是自己的前缀). 每个单词长度不会超过10. Trie树的模板题.这个题内存把控不好容易MLE. ...

  7. Prolog&Epilog

    这篇博客会简单介绍一下Prolog&Epilog 然后再简单介绍下我对于程序在计算机中到底如何运行的一些理解(因为自己之前也从来没有接触过这些方面的知识,所以如果有讲的不对的地方希望大家能够帮 ...

  8. luogu2893 [USACO08FEB]修路Making the Grade

    ref #include <algorithm> #include <iostream> #include <cstring> #include <cstdi ...

  9. (英文排版测试)Lorem Ipsum

    Lorem Ipsum Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis tincidunt consequat pretiu ...

  10. Farey sequences

    n阶的法里数列是0和1之间最简分数的数列,由小至大排列,每个分数的分母不大于n. Stern-Brocot树(SB Tree)可以生成这个序列 {0/1,1/1} {0/1,1/2,1/1} {0/1 ...