concept component in category isomorphic web applications

appears as: components, components, component, The component, component, The component
Isomorphic Web Applications: Universal Development with React

This is an excerpt from Manning's book Isomorphic Web Applications: Universal Development with React.

11.  React renders the components.

Figure 4.3. Using props.children to render components at runtime

A.1.2. Routing in components

The basics of React Router 4 are similar to those of React Router 3. You declare your routes using a Route component. You give it a path and a component to render. The big change is in where you declare your routes. In version 3, you have a single, centralized routes file. In version 4, you declare your routes inside the appropriate component. The following listing shows how you’d take the routes from the sharedRoutes.jsx file and put them in app.jsx instead.

Listing A.2. Declare the routes—components/app.jsx
// ... other code import { Link, Route, withRouter } from 'react-router-dom'; #1 import Cart from '../components/cart'; #2 import Products from '../components/products'; #2 import Profile from '../components/profile'; #2 import Login from '../components/login'; #2 const App = (props) => { return ( <div> <div className="ui fixed inverted menu"> <h1 className="header item">All Things Westies</h1> <Link to="/products" className="item">Products</Link> <Link to="/cart" className="item">Cart</Link> <Link to="/profile" className="item">Profile</Link> </div> <div className="ui main text container"> <Route path="/" exact component={Products} /> #3 <Route path="/products" component={Products} /> #4 <Route path="/cart" component={Cart} /> #4 <Route path="/profile" component={Profile} /> #4 <Route path="/login" component={Login} /> #4 </div> </div> ); }; export default withRouter(App); #5 #1 Imports the Route component and the withRouter higher-order component #2 Imports the various app components used in the routes #3 For paths that would result in multiple matches, make sure to use the exact option. #4 Each Route takes a path and a component. #5 Wraps App in the HOC withRouter. This ensures your components have access to the history and location props. !@%STYLE%@! {"css":"{\"css\": \"font-weight: bold;\"}","target":"[[{\"line\":2,\"ch\":8},{\"line\":2,\"ch\":25}],[{\"line\":3,\"ch\":8},{\"line\":3,\"ch\":25}],[{\"line\":3,\"ch\":64},{\"line\":3,\"ch\":66}],[{\"line\":31,\"ch\":0},{\"line\":31,\"ch\":2}],[{\"line\":4,\"ch\":0},{\"line\":4,\"ch\":66}],[{\"line\":5,\"ch\":0},{\"line\":5,\"ch\":66}],[{\"line\":6,\"ch\":0},{\"line\":6,\"ch\":66}],[{\"line\":7,\"ch\":0},{\"line\":7,\"ch\":66}],[{\"line\":19,\"ch\":8},{\"line\":19,\"ch\":66}],[{\"line\":20,\"ch\":8},{\"line\":20,\"ch\":66}],[{\"line\":21,\"ch\":8},{\"line\":21,\"ch\":66}],[{\"line\":22,\"ch\":8},{\"line\":22,\"ch\":66}],[{\"line\":23,\"ch\":8},{\"line\":23,\"ch\":66}],[{\"line\":29,\"ch\":15},{\"line\":29,\"ch\":26}],[{\"line\":9,\"ch\":18},{\"line\":9,\"ch\":19}],[{\"line\":26,\"ch\":2},{\"line\":26,\"ch\":3}],[{\"line\":29,\"ch\":29},{\"line\":29,\"ch\":30}],[{\"line\":29,\"ch\":64},{\"line\":29,\"ch\":66}],[{\"line\":35,\"ch\":0},{\"line\":35,\"ch\":2}]]"} !@%STYLE%@!