Backend routing

In the preceding example, we implemented a single request handler in the server that responded to requests for the root URL (/). Obviously your application is going to need to handle more than a single route. You learned how to use the react-router package for routing in the previous chapter. Now, you're going to see how to use the router in Node.js.

First, let's take a look at the main app component:

import React, { PropTypes } from 'react'; import { Link } from 'react-router'; const App = ({ header, content }) => ( <section> <header> {header} </header> <main> {content} </main> </section> ); App.propTypes = { header: PropTypes.node.isRequired, content: PropTypes.node.isRequired, }; App.defaultProps = { header: (<h1>App</h1>), content: ...

Get React and React Native now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.