-
-
Notifications
You must be signed in to change notification settings - Fork 10.6k
Go back to <Routes><Route/><Routes> #112
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
Comments
Yeah, the more I'm using React the more I've been feeling like we should bring back |
👍 from me (obviously). I think Routes should not take a handler object, mostly because it doesn't need to. Separating the route configuration (paths/names/handlers) from any runtime router flags (like |
A Routes component would also be the logical place to add default handlers for errors and not found urls. |
👍 |
I should add that the default |
Vote no on proposition I am opposed to a "notFound" handler. I still want my not-found handling to be wrapped inside my application chrome. Today, you just check if your root handler has an render: function() {
return (
<div>
<h1>My Site!</h1>
{this.activeRouteHandler() || this.renderNotFound()}
</div>
);
} If we have Same for errorHandler Let the handler with an error tell you there was an error. I want to give the user good information about the error and keep them in the UI they were at. If we have some ErrorHandler up at the top, then all of your nested UI gets blown away. Vote yes to Routes Handler! Having something rendered all the time is the path to least surprise, if something isn't rendering, its your code you sort through, not stuff in the router. It also gives you an opportunity to do any "notFound" and "error" handling you want, inside of your application layout. You always have an application, I can't see any benefit in not always having something to render that fits within the nesting paradigm. |
Additionally, imagine these docs:
|
👍 for Route/Routes and also keeping error and 404 handling out of the routes config |
👍 👍 Completely agree, @rpflorence. |
Notice I didn't call the But there is currently a small hole and it is: "what do you render when there's nothing else to render?". Currently we just render Is it a hole worth plugging? Probably not. That's why I said "if Anyway, the whole reason for separating |
What I want to avoid is this in every app: <Routes>
<Route handler={App}>
</Route>
</Routes> That would be the new required boilerplate for pretty much everything.
I don't think its confusing to document that Routes is just like Route but also contains the config options. I do think it is confusing (currently) that the positioning in the hierarchy of a Route changes the properties that matter. I see your point on defaultHandler, if somebody just never provides a
|
Here's some code to talk about, <Routes handler={Root}>
<Route name="app" path="/" handler={App}/>
<Route name="admin" handler={Admin}/>
</Routes> v. <Routes defaultHandler={NotFound}>
<Route name="app" path="/" handler={App}/>
<Route name="admin" handler={Admin}/>
</Routes> I much prefer the first because the user gets an idiomatic place to deal with the lack of an I realize we already "do something about it" by way of |
Fair enough. That's probably what most people will use it for anyway. I can't really think of any other use cases. Just to clarify, your examples aren't equivalent. They should be: <Routes handler={Root}>
<Route name="app" path="/" handler={App}/>
<Route name="admin" handler={Admin}/>
<Route handler={NotFound}/>
</Routes> v. <Routes defaultHandler={NotFound}>
<Route handler={Root}>
<Route name="app" path="/" handler={App}/>
<Route name="admin" handler={Admin}/>
</Route>
</Routes> The second one makes it more obvious to me what's going on. It isn't currently obvious to users where to put Additionally, you could keep the boilerplate to a minimum by just doing: // Declare your routes just like we do now.
var routes = (
<Route ... />
);
React.renderComponent(<Routes routes={routes}/>, document.body); The |
I might also point out that in the first example your |
|
❤️ :) |
Fixes remix-run#112. Test Plan: Loaded each of the examples and clicked around. npm test too.
Proposal
Bring back
<Routes/>
instead of "overloading"<Route/>
with two roles. Currently the rootRoute
is really the only thing doing anything interesting, the childRoute
s are just config.Justification
Route
accepts props that are meaningless to child routes, likelocation
Route
, primarily the props, is more confusing than documentingRoute
andRoutes
Route
more extensible seems like it'd be easier since it'll be an empty component with a few propTypes.Opposition
Route
all the way down is simpler for consumersQuestions
Should
Routes
take ahandler
v.
I don't know all the implications of not having a root handler that is always active, and always rendered.
The text was updated successfully, but these errors were encountered: