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. 如何使用CSS Sprites技术进行图片合并

    http://jingyan.baidu.com/article/066074d6757654c3c21cb02d.html

  2. share js 分享代码

    (function(){ var $doc = $(document); var shareHandlers = { 'twitter': function(prop,shareUrl){ var D ...

  3. 原生js实现的放大镜效果

    这是我用原生js写的放大镜效果,与各种各样的框架技术相比,我喜欢使用原生的js,在这里,想和大家一起谈谈原生和框架技术的理解与个人喜好. <!DOCTYPE HTML><html&g ...

  4. ASP.net 中关于Session的存储信息及其它方式存储信息的讨论与总结

    通过学习和实践笔者总结一下Session 的存储方式.虽然里面的理论众所周知,但是我还是想记录并整理一下.作为备忘录吧.除了ASP.net通过Web.config配置的方式,还有通过其它方式来存储的方 ...

  5. ThinkPHP实现RBAC

    RBAC: role base access control   基于角色的用户访问权限控制 不同人员登录系统要显示不同的菜单项目 1.传统方式权限设置: 具体操作权限与用户直接联系:

  6. vsftpd 访问 权限控制

    vsftpd 重启命令 service vsftpd  start|restart|stop vsftpd 关于权限控制,有两个文件分别设置,都会起作用 /etc/vsftpd/user_list / ...

  7. 自己动手开发编译器(五)miniSharp语言的词法分析器

    稍微说明一点,整型常量和上面的标识符的词法,在调用lex.DefineToken时都多传了一个参数.这个参数是可选的描述信息,如果不传会直接使用正则表达式的字符串形式.而标识符的正则表达式有4万多个字 ...

  8. 转:Visual C++ sprintf()函数用法

    将字串格式化命令.sprintf 是个变参函数,使用时经常出问题,而且只要出问题通常就是能导致程序崩溃的内存访 问错误,但好在由sprintf 误用导致的问题虽然严重,却很容易找出,无非就是那么几种情 ...

  9. chrome 打不开网页

    右键单击Chrome在桌面的快捷方式,在在但中选择“属性”,在对话框的“目标”项目中追加:-no-sandbox     大家比较熟悉的解决方法有配置 Hosts 文件和使用FQ软件两种,配置 Hos ...

  10. 一个简单的以User权限启动外部应用程序

    BOOL ExecuteAsUser(LPCWSTR lpszUserName, LPCWSTR lpszPassword, LPCWSTR lpszApplication, LPCWSTR lpsz ...