[React] React router:named Components

Source: Internet
Author: User



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={{headerbody: otherbody}}></route>


The ' 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


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.