Repository: flutter
Issue: [go_router_builder] Generate a method to return the matching `GoRoute` or `GoRouteData` from a location
Labels: c: new feature,package,c: proposal,P3,p: go_router_builder,team-go_router,triaged-go_router

<!-- Thank you for using Flutter!

     If you are looking for support, please check out our documentation
     or consider asking a question on Stack Overflow:
      * https://flutter.dev/
      * https://api.flutter.dev/
      * https://stackoverflow.com/questions/tagged/flutter?sort=frequent

     If you have found a bug or if our documentation doesn't have an answer
     to what you're looking for, then fill out the template below. Please read
     our guide to filing a bug first: https://flutter.dev/docs/resources/bug-reports
-->

## Use case

<!--
     Please tell us the problem you are running into that led to you wanting
     a new feature.

     Is your feature request related to a problem? Please give a clear and
     concise description of what the problem is.

     Describe the alternative solutions you've considered. Is there a package
     on pub.dev/flutter that already solves this?
-->

Let's consider an app with 2 routes:

```dart
// A route to log in when the user is logged out.
@TypedGoRoute<LoginRoute>(path: '/login')
class LoginRoute extends GoRouteData {
  const LoginRoute();

  @override
  Widget build(BuildContext context) => const LoginScreen();
}

// The home route the user sees when logged in.
@TypedGoRoute<HomeRoute>(path: '/home')
class HomeRoute extends GoRouteData {
  const HomeRoute();

  @override
  Widget build(BuildContext context) => const HomeScreen();
}

final router = GoRouter(
  routes: $appRoutes,
  redirect: (GoRouterState state) {
    // Here we only have access to the state which contains strings (`location`).
  
    if(userIsLoggedIn()) {
      // Verify the route is not the login route.
    } else {
      // Verify the route is not the home route.
    }
  },
);
```

This generates the extensions:

```dart
extension $LoginRouteExtension on LoginRoute {
  static LoginRoute _fromState(GoRouterState state) => const LoginRoute();

  String get location => GoRouteData.$location(
        '/login',
      );

  void go(BuildContext context) => context.go(location, extra: this);

  void push(BuildContext context) => context.push(location, extra: this);
}

// Home extension
// ...
```

There is no way to get the route from the URL/location (including nested ones) and this forces us to do some logic on the URL/location string which I think defeats the purpose of `go_router_builder`.

The `route` is actually accessible with `state.extra`. But it is available only if the code use `push`/`go` of the generated extension.
This is not the case when the user enters the URL by hand in the address bar/clicks on the back or forward button of the browser/refreshes the page.
Also, because of this issue (https://github.com/flutter/flutter/issues/106790), it is not possible to use the generated `go` and `push` method from the extensions with an abstracted code.

In short, we cannot rely on `state.extra` to get the route.

## Proposal

It would be very useful to generate a method that parses an URL/location and returns the correct route.

```dart
final router = GoRouter(
  routes: $appRoutes,
  redirect: (GoRouterState state) {
    final route = $someMethod$(state.location);
    // Typed logic 
  },
);
```