-
-
Notifications
You must be signed in to change notification settings - Fork 10.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Route component #40
Route component #40
Conversation
don't merge this yet, we need to reword the commit messages with [changed], [added] or [removed] so they go in the changelog automatically when I do a release |
also, do we want to add a |
The Router interface is deprecated in favor of using <Route> components directly with React.renderComponent.
webpack-karma was bundled everything into every single spec we had (5 copies of react, 5 copies of the router, etc). While having to put every spec we want to require into the specs/main.js file isn’t ideal, it works. I imagine there is some configuration option I’m unaware of that removes the need for this workaround. Also, Promise was not being required, some environments have it, some don’t.
@rpflorence Good call on keeping the |
I personally find this more confusing because now Route sometimes describes what routes exist and sometimes renders an actual component to the DOM? It would make more sense to me if
Then there's an obvious place to support passing in a path for server rendering, etc:
(Other props could also be added to that |
Or maybe I'm misunderstanding how nested routes work? It's not clear to me whether the top-level component behaves differently from the others. |
@spicyj Yes, the top-level component acts as the router for all routes underneath it. All other routes are simply used for configuration. Using the same component class has some nice benefits, including the fact that it makes it easy to split out your routes into multiple |
I'm not sure what you mean. Even in my idea you can break up the routes and write: var userRoutes = (
<Route name="users" handler={Users}>
<Route name="user" handler={User} path="/user/:id"/>
</Route>
);
var routes = (
<Route handler={App}>
<Route name="about" handler={About}/>
{userRoutes}
</Route>
);
React.renderComponent(<Router routes={routes} />, document.body); Of course it's nice if any level of route can be composted within another, but the actual rendering responsibility seems to be a different concern. You could also imagine that in another world, the route configuration would be plain JSON, and then you would need to have a separate component to render them. Basically, there's no reason that the subroutes need to be React components at all, so it seems confusing to conflate the two concepts. |
This PR simplifies things quite a bit.
There are now only two types of React components:
Route
andLink
. Both components are able to be rendered normally usingReact.renderComponent
. Everything that was previously encapsulated inRouter
is now inRoute
, but only the top-level routes ever render. All others are used for configuration, as before.The recommended usage is now:
which should be more familiar to React users than our custom
Router#renderComponent
method.This work should help with #38 and #34.