In this lesson we'll learn how to render multiple component children from a single route.

Define a named component by "components":

<Route path="/other" components={ {header: Other, body: OtherBody}}></Route>

'header' and 'body' are the key.

Render:

const Container = (props) => <div>{props.header}{props.body}<Links /></div>;

------------------

import React from 'react';
import {hashHistory, Route, Router, Link, IndexRoute} from 'react-router'; const Home = () => <h1>Home</h1>;
const HomeBody = () => <h3>HomeBody</h3>;
const Other = () => <h1>Other</h1>;
const OtherBody = () => <h3>OtherBody</h3>; const Container = (props) => <div>{props.header}{props.body}<Links /></div>; const Links = () =>
<nav >
<Link to="/">Home</Link>
<Link to="/other">Other</Link>
</nav>; class App extends React.Component {
render(){
return(
<Router history={hashHistory}>
<Route path="/" component={Container}>
<IndexRoute components={ {header: Home, body: HomeBody} }></IndexRoute>
<Route path="/other" components={ {header: Other, body: OtherBody}}></Route>
</Route>
</Router>
);
}
} export default App;

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

  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+redux+router+webpack+antd环境搭建一版

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

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

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

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

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

  6. [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 ...

  7. react react使用css

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

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

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

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

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

随机推荐

  1. ajax调用webservice(二) 跨域。

    所需工具与项目结构同(一). service.asmx中代码如下: using System; using System.Collections.Generic; using System.Web; ...

  2. goldengate单向复制文档

    1:实验环境 2:实验步骤 --下面的2.1-2.2步骤,都需要在源端和目标端分别执行. 2.1:准备工作 2.1.1 建表空间 create tablespace ogg datafile '/u0 ...

  3. CSS3过渡效果实现菜单划出效果

    下载地址 这是大体上的原理,当然案例比这个多 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" & ...

  4. JNDI--Java命名和目录接口

    JNDI主要用于在容器中配置某些资源,让所有项目可以使用.JNDI可以提供: 1:数据库连接池.            自定义连接池             第三方连接池 Dbcp           ...

  5. 关于laravel框架的Auth::attempt验证失败

    按照官方文档进行认证 发现不管怎么样都是失败 if (Auth::attempt(array('email' => $email, 'password' => $password), tr ...

  6. Redis同步(主从复制)

    目录1.Replication的工作原理2.如何配置Redis主从复制3.应用示例 1.Replication的工作原理在Slave启动并连接到Master之后,它将主动发送一条SYNC命令.此后Ma ...

  7. 高级应用与部署 —— 主程序与web目录分离

    在网站部署中,考虑网站的安全行问题,可以将您的网站主程序与web目录分离,使主程序在web目录之外,从而提高网站的安全性. 分离方法 1.将phpcms v9中程序主框架目录phpcms移动至web目 ...

  8. JQuery里属性赋值,取值prop()和attr()方法?

    1.赋值的时候 如果是<input type="checkbox" checked>这样的只有属性名就能生效的属性 推荐prop,即:$('input').prop(' ...

  9. 实现单实例多线程安全API问题

    前阵子写静态lib导出单实例多线程安全API时,出现了CRITICAL_SECTION初始化太晚的问题,之后查看了错误的资料,引导向了错误的理解,以至于今天凌晨看到另一份代码,也不多想的以为singl ...

  10. C++服务器linux开发环境管理

    在游戏服务器开发中,跨平台不是必须的.线上游戏既有windows下的C++..Net服务器也有linux下的C++.go.erlang服务器.但是无论如何都要保证开发环境和线上运行环境的一致,否则不同 ...