I have a React application where main.js
calls app.js
--which acts as a parent component--as can be seen here:
React.render(<APP />, document.getElementById("main"));
Now I need to set up React Router so that app.js
will handle routing within the app.
Present setup
To set up my routes I have created routes.js
, which contains the following code:
var Router = require('react-router');
var Route = Router.Route;
var routes = (
<Route handler={App}>
<Route path="/" handler={home}/>
</Route>
);
module.exports = routes;
In app.js
I imported routes and added RouteHandler
as in the documentation:
var React = require('react');
var Router = require('../routes.js');
var RouteHandler = Router.RouteHandler;
var APP = React.createClass({
render: function() {
return (
<RouteHandler/>
);
}
});
module.exports = APP;
I am having trouble understanding this code in the documentation:
Router.run(routes, Router.HashLocation, (Root) => {
React.render(<Root/>, document.body);
});
Since I have already called the <app />
component from within the main
component I want to handle all of the routing in the app
component. I think the above code is transferring handler={component_to_render}
through Root
. But how do I configure my code in app.js
to transfer the route to <RouteHandler/>
?
My whole setup might be wrong, so any guidance will be appreciated.