IndexRoute allows us to define a default child component to be rendered at a specific route when no other sub-route is available.

When Home page display, we also make About component as default Route to dsiplay, only when use click Contact link, then swith to Contact Route:

import React from 'react';
import {hashHistory, Route, Router, Link, IndexRoute} from 'react-router'; const Home = (props) => <div><h1>Home</h1><Links></Links>{props.children}</div>;
const About = () => <div><h1>About</h1></div>;
const Contact = () => <div><h1>Contact</h1></div>; const Links = () =>
<nav >
<Link activeStyle={{color: 'green'}} to="/">Home</Link>
<Link activeClassName="active" to="/contact">Contact</Link>
</nav>; class App extends React.Component {
render(){
return(
<Router history={hashHistory}>
<Route path="/" component={Home}>
<IndexRoute component={About}></IndexRoute>
<Route path="contact" component={Contact}></Route>
</Route>
</Router>
);
}
} export default App;

[React] React Router: IndexRoute的更多相关文章

  1. ReactJS React+Redux+Router+antDesign通用高效率开发模板,夜间模式为例

    工作比较忙,一直没有时间总结下最近学习的一些东西,为了方便前端开发,我使用React+Redux+Router+antDesign总结了一个通用的模板,这个技术栈在前端开发者中是非常常见的. 总的来说 ...

  2. Nginx支持 React browser router

    修改nginx配置文件,添加try_file配置如下,即可实现对 React browser router 的支持. location / { root /var/www/mysite; try_fi ...

  3. React+React Router+React-Transition-Group实现页面左右滑动+滚动位置记忆

    2018年12月17日更新: 修复在qq浏览器下执行pop跳转时页面错位问题 本文的代码已封装为npm包发布:react-slide-animation-router 在React Router中,想 ...

  4. react 装 router - yarn add react-router-dom@next

    react 装 router yarn add react-router-dom@next

  5. [React] react+redux+router+webpack+antd环境搭建一版

    好久之前搭建的一个react执行环境,受历史影响是webpack3.10.0和webpack-dev-server2.7.1的环境,新项目准备用webpack4重新弄弄了,旧的记录就合并发布了(在没有 ...

  6. react react使用css

    在react 中使用css有以下几种方法 第一种全局使用 app.js import React from 'react'; import Router from "./router&quo ...

  7. React/React Native 的ES5 ES6写法对照表

    //es6与es5的区别很多React/React Native的初学者都被ES6的问题迷惑:各路大神都建议我们直接学习ES6的语法(class Foo extends React.Component ...

  8. React/React Native 的ES5 ES6写法对照表-b

    很多React/React Native的初学者都被ES6的问题迷惑:各路大神都建议我们直接学习ES6的语法(class Foo extends React.Component),然而网上搜到的很多教 ...

  9. [React] React Fundamentals: Integrating Components with D3 and AngularJS

    Since React is only interested in the V (view) of MVC, it plays well with other toolkits and framewo ...

  10. React: React组件的生命周期

    一.简介 在前面的第二篇博文中对组件的生命周期虽然做了一个大略介绍,但总感觉说的过于简单,毕竟生命周期是React组件的核心部分.在我们熟练使用React挂载和合成组件来创建应用表现层的过程中,针对数 ...

随机推荐

  1. https加密

    对称加密  客户端和服务器使用同一把钥匙,加密算法公开 非对称加密  不同钥匙,公钥加密的私钥可以打开 私钥加密的公钥可以打开 HTTPS关键: 1. 要传输的业务数据,使用对称加密. 客户端生成私钥 ...

  2. gc内存回收机制

    判断哪些对象可回收 GC是通过对象是否存活来决定是否进行回收,判断对象是否存活主要有两种算法:引用计数算法.可达性分析算法 引用计数算法 引用计数的算法原理是给对象添加一个引用计数器,每被引用一次计数 ...

  3. C# LINQ 基本操作实例

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...

  4. IO流文件字符输入输出流,缓冲流

    由于字节输入输出流在操纵Unicode字符时可能有乱码现象 于是就有了操作字符的输入输出流 Reader ,Writer和他们的子类FileReader,FileWrite(其实就是用来辅助构造的 W ...

  5. C++拾遗(六)函数相关(1)

    返回值 C++规定返回值不能是 数组.但可以是其它任何类型(包括结构体和对象). 通常,函数将返回值复制到指定的CPU寄存器或内存单元中,然后调用函数调用该内存单元的值. 函数原型 参数列表中可以不包 ...

  6. IIS 中asp.net的一些配置

    安装了IIS之后, 添加了虚拟目录然后运行页面, 出现了一点儿错误, 好像是不认识aspx文件, 把aspx文件当成是xml文件处理. 无法显示 XML 页. 使用 XSL 样式表无法查看 XML 输 ...

  7. C# 中显示实现接口

    接口的实现分为显示实现和隐式实现 用显示实现接口的目的就是为了,当一个类中实现多个具有相同方法的接口时,能够区分开来 在调用的时候,必须用接口调用. class Program { static vo ...

  8. python: list[-1] 与 list[-1:] 的区别

    >>> l '3.542485\t1.977398\t-1\r\n' >>> l.split() ['3.542485', '1.977398', '-1'] &g ...

  9. 网站注册信息的JS全码

    <div class="box_index2">                <div class="login_title">    ...

  10. 解决TextView与RadioGroup不对齐的问题

    TextView和RadioGroup是在同一个LinearLayout中的,控件摆放方式是android:orientation="horizontal",虽然三个控件是水平摆放 ...