Add support for Fragments and support route grouping#122
Add support for Fragments and support route grouping#122Fionoble wants to merge 3 commits intopreactjs:mainfrom
Conversation
rschristian
left a comment
There was a problem hiding this comment.
Thanks, but I'd be quite against adding anything like this.
<Router> should more or less act like a switch statement, matching direct descendants and choosing which of them is active. Adding arbitrary nesting a) reduces perf considerably for matching, as each sub tree now needs to be evaluated and b) deviates from that simplicity considerably.
There was a problem hiding this comment.
I do generally like this kind of functionality as it would allow us to create similar patterns to react-router. Currently we're looking at ProtectedRoutes or ProtectedRoute, however I can see a case for doing <Route><Route /></Route> in future versions as DX wise it's quite neat to form these common layouts etc.
Not a right now thing. Generally the thing I like about allowing for this approach is that we can share common functionality among routes, be that an auth requirement or a common data-slice over context.
I do see Ryans point of simplicity here as we've tried keeping iso as small and performant as possible, though I don't think the performance should be highly impacted as this render method shouldn't invoke a whole lot. The size will def be impacted
Can do this pretty easily already by just creating an That, and nested routers (where appropriate), have been what folks have been using to land that behavior without any issue to my knowledge; it's what I've been using to land that behavior without any real issue.
If you're using this w/ SSR (no idea if many people are, but nothing's stopping them) then that becomes a bigger concern. Unlikely to immediately be a bottleneck of course but trying to recursively search for children is a really weird default from a perf prospective as it'd be a fairly niche feature that's often searching dead-ends. As for aligning with react-router, we already deviate in a million ways, I don't see any particular value in trying to align here in this specific area. AFAIK, RR generally just works with Preact and users can use it if they prefer the API. This would be the sort of thing I'd want to veto, I really don't think it's a positive addition. |
Co-authored-by: Jovi De Croock <decroockjovi@gmail.com>
Co-authored-by: Jovi De Croock <decroockjovi@gmail.com>
|
All good, just figured it would be a nice DX improvement to the library. There's no helpful error or feedback when you do this to other router conventions so adding support for it was my approach. I can close this if it's not desirable though. |
This pull request improves the router's ability to handle routes nested inside
Fragmentcomponents or arbitrary wrapper elements, ensuring that all routes are recognized regardless of their nesting structure. It also adds comprehensive tests to verify this new behavior.Router nesting support:
src/router.jsto recursively flatten and collect allRoutecomponents from nested children, including those insideFragmentor wrapper components, before matching routes. This ensures nested routes are now supported. [1] [2]Testing improvements:
test/router.test.jsto verify that routes nested withinFragmentcomponents, wrapper elements (likediv), and deeply nested structures are correctly recognized and rendered by the router.This now supports the following structure: