Reputation: 3878
What is the difference in writing react-router in following different ways?
1.) As seen in react-router github page
<Router history={browserHistory}>
<Route path="/" component={App}>
<Route path="about" component={About}/>
<Route path="users" component={Users}>
<Route path="/user/:userId" component={User}/>
</Route>
<Route path="*" component={NoMatch}/>
</Route>
</Router>
import TodoApp from './TodoApp';
import TodoMain from './TodoMain';
export default {
path: '/',
component: TodoApp,
indexRoute: { component: TodoMain },
childRoutes: []
};
import { Route, IndexRoute } from 'react-router';
import TodoApp from './TodoApp';
import TodoMain from './TodoMain';
export default (
<Route path="/" component={TodoApp}>
<IndexRoute component={TodoMain} />
</Route>
);
Upvotes: 1
Views: 73
Reputation: 8376
Just take a look at the Alternate Configuration section on official docs. It explains that react-router can either accept JSX or a plain-object, each having two mandatory properties: path
and component
. The indexRoute
property of that plain-object is "replaced" (in fact, it's not) by <IndexRoute />
component; and childRoutes
is the same as children
prop of a component which is filled by whatever is encapsulated into the component.
So, the
export default {
path: '/',
component: TodoApp,
indexRoute: { component: TodoMain },
childRoutes: []
};
configuration can be written in JSX way:
export default (
<Route path="/" component={TodoApp}>
<IndexRoute component={TodoMain} />
</Route>
);
Upvotes: 1