O'Reilly logo

React and React Native by Adam Boduch

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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: ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required