-
-
Notifications
You must be signed in to change notification settings - Fork 10.6k
Separate <Routes> component from <Route> spec #118
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
Conversation
(partial-app-loading is as broken as before; the other examples work.) |
); | ||
|
||
route.dispatch('/').then(function () { | ||
assert(route.props.customProp); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test was previously not asserting anything useful, as far as I can tell.
is |
Awesome work @spicyj :) I wonder if having to specify the path |
@rpflorence My preferred usage would be: React.renderComponent(<Routes routes={routes}/>, ... ) Otherwise, componentDidMount: function () {
setupRoutes(this.props.routes || this.props.children);
} to |
I know its easy for us to add, but you know me and documenting things. I'd rather it was "just JSX" and we dont' document anything than "also, you can pass the children in as a property instead of as children". I just don't want to start making shortcut properties all over the place when there is a "normal" JSX way of doing something. |
Come to think of it ... Does that work? [2 minutes later...] Yes it does. |
@rpflorence Ah, yes. I should've seen that! :) Good catch. |
Personally, I like it. Every other routable path is has a path (or name) listed; it seems fitting that the root should too. |
README needs an update but I could do that in a different commit I suppose. I haven't looked too much at the code but I'm 👍 on the API |
I'd like to be able to leave out the |
We can only default the path to '/' if there is only one |
In Flask you write
without the App route getting an implicit |
I'd like to be able to do this: <Routes>
<Route handler={App}>
<Route name="home" handler={Home} />
<Route name="about" handler={About} />
</Route>
</Routes> and leave
I don't think that's confusing at all. |
@spicy, currently we have default '/' for the root route, but |
Because there is no required single root route, having an automatic <Routes>
<Route handler={App}>
<!-- more routes -->
</Route>
</Routes> Everything works great, and my app route has an implicit path of But then I add an admin section to the app: <Routes>
<Route handler={App}>
<!-- more routes -->
</Route>
<Route handler={Admin}>
<!-- more routes -->
</Route>
</Routes> :trombone: Which one gets the I wish we still had a required root handler with an implicit path of |
Adding <Routes>
<Route path="/" handler={App}>
<!-- more routes -->
</Route>
<Route path="/" handler={Admin}>
<!-- more routes -->
</Route>
</Routes> The predictability doesn't come from putting explicit paths on every route. Instead, it comes from how you order them, top to bottom. This is exactly how it's done in a lot of web frameworks, e.g. Flask, Sinatra, etc. You scan your routes top to bottom. Predictability is already one of the router's greatest strengths. The most deeply nested route that matches the URL is the one that renders. Simple. |
Your last example looks obviously wrong to me because you have two routes with Can you help me understand when you would want this hierarchy?
What does |
@spicyj exactly. I can't stop on the root route ... it gives you a place to deal with a visit from the user no matter what, whether that's to redirect in a transition hook, or render some empty "home" or "not found" template if nothing else matches, all in the same nested structure devs are used to. |
It helps when you're thinking about things in terms of UI instead of paths. <Routes>
<Route handler={LoggedOutUI}>
<Route name="login" handler={Login} />
<Route name="forgot-password" handler={ForgotPassword} />
</Route>
<Route handler={LoggedInUI}>
<Route name="home" handler={Home} />
<Route name="about" handler={About} />
</Route>
</Routes> In this example, I'm totally focused on UI. I don't care what the path is because it's not important. The only thing I care about is that the |
@mjackson so what happens when I just visit |
Yes. It didn't take you long to reason it out. I don't understand why you think it will be difficult for others. In willTransitionTo: function (transition) {
if (transition.path === '/') transition.redirect('login');
} |
Because you and I are used to MAGIC Alright, I will concede. I'm fine with no root routes and the first "root" route getting a default That means transitioning from 0.4 -> 0.5 0.4.x <Route location="history" handler={App}>
<Route name="dashboard" handler={Dashboard} />
</Route> 0.5.x <Routes location="history">
<Route handler={App}>
<Route name="dashboard" handler={Dashboard} />
</Route>
</Routes> Seems reasonable. If people start getting confused about where |
😆 Sounds good. |
So are we just saying "routes without a path or name default path to |
Re: last comment, yes, yes we are. @spicyj, please update the PR to put "/" back as the default path and lets merge this sucker. Unless you've still got your boxing gloves on, then by all means ... |
Last thing I'll say: if you really want to put |
we're still very early in this project, it'll be easy for us and others to update to a version that doesn't default route paths to |
Fixes remix-run#112. Test Plan: Loaded each of the examples and clicked around. npm test too.
Rebased and changed to make |
sweet, I'm going to amend this commit with some README updates and commit it manually don't click the merge button @mjackson |
queue final fantasy level up riff, welcome to the project @spicyj :D |
Thanks @spicyj! Great work! |
Fixes #112.
Test Plan: Loaded each of the examples and clicked around. npm test too.