I am having difficulty knowing the flow of react-router by (https://github.com/rackt/react-router).
If i have 2 files: routes.js, app.js(entry component) as below:
var Router = require('react-router');
var Route = Router.Route;
var routes = (
<Route handler={App}>
<Route path="/" handler={home}/>
</Route>
);
module.exports = routes;
app.js
var React = require('react');
var Router = require('../routes.js');
var RouteHandler = Router.RouteHandler;
var App= React.createClass({
render: function(){
return (
<RouteHandler/>
)
}
});
module.exports = App;
How does the app component gets called? As of traditional way i use following code to render "app" component in app.js.
React.render(
<App />, document.getElementById('main')
);
Now what i dont understand is what is the following code doing. Is it replacement of traditional way of rendering, i need to use following code to listen to url and render app.js but not the above code?
Router.run(routes, Router.HashLocation, (Root) => {
React.render(<Root/>, document.body);
});
What if i am using another js file "main.js" to render "app.js" and now i want to use app.js to handle all the route how do i do it. Mean to say i want to render what ever the route is passed in app.js.
My code in main.js is below:
React.render(
<APP />, document.getElementById('main')
);