Replies: 3 comments
-
@esDotDev thanks for the thoughtful dig into another routing system! There are lots of interesting ideas here. I do resist adding new ideas to GR unless there is also new functionality unlocked. Having multiple ways of doing the same thing is a cognitive load for the user that I'm trying to avoid as much as possible. That said, for things that GR can't already do, I'd like to know more. re: most specific match rule: go_router only allows you to match a single rule. I got tired of arranging my table according to the order I wanted things to match, so I got rid of that altogether. If there's multiple matches, it's an error that's reported to the developer. re: index routes: you can do that today via redirection, e.g. /family => /family/[first-family-id], or by just providing a builder that builds what the "index" route would build. re: relative links: I like this idea but I'm not quite sure how to implement it... re: multiple sets of routes: this is interesting, too, although I'm not quite sure what problem it solves. How do you think this would work in the world of GR? re: descendant routes: this is an interesting way to spread routing -- particularly nested routing -- into different parts of the app. this is still a nut I'd like to crack w/ GR. |
Beta Was this translation helpful? Give feedback.
-
Ya these are interesting, I'm trying to think of how they look in Flutter. The key abstraction in this approach, is the idea that you can push the matching route downwards into the tree, using the I guess this Outlet does something like: Widget build(){
return GoRouter.of(context).navigator;
} And you can stick this class MyScaffold extends StatelessWidget{
Widget build(_) => Column(children: [
Text('My App Title'),
Expanded(child: GoRouterOutlet()) // <- equivalent of 'navigator' in the builder above
])
} I'm not sure if it really provides anything the Then they combine that, with the ability of having multiple
I'm not sure how this last bit looks in Flutter. I guess it is basically just some sort of WidgetSwitcher, that is tied into the current path? We can do this now with imperative code, for example: // Inside of `LeftSideMenu`
if(currentPath.contains('/users')) return UsersMenu();
if(currentPath.contains('/settings')) return SettingsMenu();
return SizedBox.shrink();
// Or, inside of `TitleBar`
if(currentPath.contains('/users')) return Text('Users');
if(currentPath.contains('/settings')) return Text('Settings');
return Text('My App Title'); Again, not sure the declarative approach enables anything we can't do imperatively, but interesting design nonetheless. |
Beta Was this translation helpful? Give feedback.
-
I could envision something like this being pretty handy: Widget build(_) => GoRouterWidgetSwitcher(
transitionBuilder: ...
routes: {
'/users/*' : Text('Users'),
'/settings/*' : Text('Settings')
}
)); I think that fundamentally gets to what they are doing, and is a nice way to declaratively react/bind your UI to the current app path. We could combine that with a Widget build(_) => GoRouterWidgetSwitcher(
child: _TitleBar()
routes: {
'/users/*' : Text('Users'),
'/settings/*' : Text('Settings')
}
)!;
...
class _TitleBar extends StatelessWidget {
Widget build() => Padding(
padding: EdgeInsets.all(24),
child: GoRouterWidgetSwitcherOutlet()) // <- The outlet renders the current match of the closes GoRouterWidgetSwitcher
} But again...is this any better than just having an optional builder? I guess both have their use cases. |
Beta Was this translation helpful? Give feedback.
-
Just had a look through the new react router, it's pretty neat how similar it is to go_router:
https://reactrouter.com/docs/en/v6/getting-started/overview
Good sign when you see everyone condensing towards the same point in the API design!
Just posting here for visibility, and maybe it will spark some inspiration or crystallize some thinking. It has some rules and features that are pretty interesting:
<Route path="*" element={<NoMatch />} />
for a 404 error. It matches everything, but is also least specific, so it always goes last. Similarly, a link tofamily/create
is considered more specific thanfamily/:familyid
. This frees up the routes table from caring so much about order of declaration or parent/child structure.https://reactrouter.com/docs/en/v6/getting-started/overview#configuring-routes
navigationBuilder
at the route level. But calling them 'index routes', with a path of "/" feel very intuitive: https://reactrouter.com/docs/en/v6/getting-started/overview#index-routes, kinda neat.https://reactrouter.com/docs/en/v6/getting-started/overview#relative-links
foo/bar/*
at the top, and then further down the tree, you finish it off.https://reactrouter.com/docs/en/v6/getting-started/overview#descendant-routes
Beta Was this translation helpful? Give feedback.
All reactions