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. 使用FileResult返回浏览器文件及乱码问题解决

    一.向客户端发送文件方法 Asp.Net 中返回文件方法 public void TxtFile(string filename) { //html文件 string path = @"E: ...

  2. W3C小组宣布:HTML5标准制定完成

    近日,W3C小组宣布已经完成对HTML5标准以及Canvas 2D性能草案的制定,这就意味着开发人员将会有一个稳定的“计划和实施”目标. Web性能工作组已经推出W3C的两个版本建议草案. Navig ...

  3. GDI+基础(2)

    使用钢笔,画笔用来填充图形内部,钢笔则用来绘制带有一定宽度,样式和色彩的线条和曲线. 可以使用标准的pens类 <%@ Page ContentType="image/gif" ...

  4. Starting nagios:This account is currently not available nagios

    nagios在启动时报错 # service nagios restartRunning configuration check…done.Stopping nagios: done.Starting ...

  5. 使用poi3.9的jar输出excel

    // 取得模板文件存放的路径 ReadFilePath = ServletActionContext.getServletContext().getRealPath(ExcelTemplateFile ...

  6. js 跨浏览操作

    /* 跨浏览器添加事件绑定  obj : 需要绑定js时间的对象 type:  欲绑定的事件类型,如:click ,mounseover 等事件  不需要添加on fn  :  触发的脚本*/func ...

  7. jquery判断页面滚动条(scroll)是上滚还是下滚

    单纯判断滚动条方向 function scroll( fn ) { var beforeScrollTop = document.body.scrollTop, fn = fn || function ...

  8. Linux下部署Symfony2对app/cache和app/logs目录的权限设置

    在linux下部署完Symfony2,可能在访问的时候会报app/logs或者app/cache目录没有写权限的错误.在linux下,如果我们在命令行登陆的用户和web应用服务器(apache.ngi ...

  9. git生成密钥

    安装 Git-1.9.4-preview20140611 1 通过 ssh-keygen 但生成的位置却是C:\Users\Admin\AppData\Local\VirtualStore\Progr ...

  10. phpEXCEL操作全解

    phpExcel中文帮助手册,列举了各种属性,以及常用的操作方法,难得是每一个都用实例加以说明,希望对大家有所帮助. phpExcel中文帮助手册,不可多得的好文章,供大家学习参考. 1.设置exce ...