-
-
Notifications
You must be signed in to change notification settings - Fork 10.3k
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
[DO NOT MERGE] Deprecate nested routes with absolute paths #3319
Conversation
This is useful for making:
All previous UI + url combinations are still possible but with some route config finagling--that's really the only trade-off (and JSF*). <Route path="inbox" component={Inbox}>
<IndexRoute component={Dashboard}/>
<Route path="/message/:id" component={Message}/>
</Route>
// becomes
<Route component={Inbox}>
<Route path="inbox" component={Dashboard}/>
<Route path="message/:id" component={Message}/>
</Route>
// or (could happen if other routes make it seem cleaner this way)
<Route path="inbox" component={Inbox}>
<IndexRoute component={Dashboard}/>
</Route>
<Route component={Inbox}>
<Route path="message/:id" component={Message}/>
</Route> Worth it? (*) JavaScript Fatigue |
I find the opposite true. In this example, I have to manually concat 3 strings in my head to understand what the URL looks like <Route path="/" component={App}>
<Route path="about" component={About} />
<Route path="inbox" component={Inbox}>
<Route path="messages/:id" component={Message} />
</Route>
</Route> Whereas if you use absolute paths exclusively (we do) it's way clearer, especially in a sufficiently large route config. <Route path="/" component={App}>
<Route path="/about" component={About} />
<Route path="/inbox" component={Inbox}>
<Route path="/inbox/messages/:id" component={Message} />
</Route>
</Route> Mixing absolute & relative feels weird, but I'd miss being able to go exclusively absolute. |
You can put a comment in there: <Route path="/" component={App}>
<Route path="about" component={About} />
<Route path="inbox" component={Inbox}>
<Route {/* path=/inbox/messages/:id */} path="messages/:id" component={Message} />
</Route>
</Route> That being said, it would be cool if there was some utility similar to |
@bensmithett I had thought about that use case a bit, and I'm not totally sure what to do there. The case we're worried about is less what you're doing, and more something like: <Route path="/inbox" component={Inbox}>
<Route path="/not-inbox" component={SomethingElse} />
</Route> IMO this is quite confusing. |
@taion is that necessarily a bad thing? I didn't think component nesting necessarily needed to dictate URL structure (via docs) <Route path="/inbox" component={Inbox}>
<Route path="/inbox/settings" component={InboxSettings} />
<Route path="/message/:id" component={Message} />
</Route> @timdorr yeeeah, but self-documenting code > comments! (feel free to point me at other discussions, totally jumping in from the sidelines here 😄) |
@bensmithett See #3172 for reference. I think the contributing team is all sold on this, so it's going to happen. Personally, I even think it's dangerous to support nested absolute routes, as it's more likely to lead to error-prone behavior, pain, and sadness for all involved. |
I'm not against them, I <3 that the urls and component nesting are not coupled, that was a big deal to me when I first wrote any of the router code. But, I'm okay to see them go too since you can still accomplish the same UI + url combos w/o them. Regarding the "all of them are absolute", I've seen quite a few people who prefer to do it this way ... wonder what it would look like if we allowed absolute urls as long as they matched their parent perfectly. My main concern with this PR is that the benefits aren't huge anymore (we thought some other stuff depended on this, but turns out it doesn't), and to the folks using absolute paths, us removing them is just irritating. |
Though I'd be slightly :sadface: (it's a feature I like & get value from, haven't experienced any pain) if this PR shipped I'd survive. Trade-offs gonna trade-off 😄. (Also ❤️ 🎁 🍺 core team for all your work!) |
@bensmithett mind cut/pasting that question into a new issue since it's not related, I can answer it over there. |
@ryanflorence done #3320 |
This PR is pending an update to not drop support for #3319 (comment). There's one other benefit to dropping nested absolute &c. support – it's that we can make In other words, if we take out this feature, and we want to see if whether |
So sounds like here's where we're at:
|
I'd say for (2), if we keep support for non-conflicting absolute paths, the bigger change is that things become simpler conceptually. The implementation ends up looking almost the same, it's just that we know that if a parent route doesn't match, then it's "cleaner" to say that child routes won't match either. |
I'm thinking that we should actually move the matching logic into the route classes entirely. |
As for the performance gains and simpler implementation, couldn't we also achieve this by transforming absolute routes during initialization, similar to how JSX is resolved? |
I don't think so... we actually do need to look at the parent routes. I don't know – it's maybe not such a big deal in practice. |
@@ -75,6 +75,8 @@ function routeIsActive(pathname, routes, params) { | |||
const pattern = route.path || '' | |||
|
|||
if (pattern.charAt(0) === '/') { | |||
// This code path is deprecated, but we the deprecation warning will |
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.
Looks like there is an extra we
in this comment.
Not much point keeping this open. Need a better plan before it makes sense to merge this. |
From @ryanflorence on #3246 (comment):
So I think at the end of it all, it looks like nothing strictly depends on this. It just makes a lot of things simpler, like relative link support, and lets us further optimize checking whether links are active.
So there's nothing strictly requiring this any more, but we should still do it sooner or later.