csells / go_router

The purpose of the go_router for Flutter is to use declarative routes to reduce complexity, regardless of the platform you're targeting (mobile, web, desktop), handling deep linking from Android, iOS and the web while still allowing an easy-to-use developer experience.
https://gorouter.dev
442 stars 96 forks source link

Why are there no params in topRedirect? #59

Closed KoheiKanagu closed 2 years ago

KoheiKanagu commented 2 years ago

I wanted to change the redirection in params, but params was always empty.

GoRouter(
...
    redirect: (state) {
      final foo = state.params['foo']; // always null
      final bar = state.params['bar']; // always null

      if (foo == 'foo') {
        return '/foo';
      }
      if (bar == 'bar') {
        return '/bar';
      }
      return null;
    },
  ),

https://github.com/csells/go_router/blob/8b0c70d8b9bece90f84bd4e2f52a5b3094419668/lib/src/go_router_impl.dart#L287-L296

Could you consider adding params? like this.

GoRouterState(
  location: loc,
  // trim the query params off the subloc to match route.redirect
  subloc: Uri.parse(loc).path,
  params: Uri.parse(loc).queryParameters,
),
csells commented 2 years ago

I think that's a reasonable request. I'll drop that into my next release.

csells commented 2 years ago

fixed in v2.0.0. @KoheiKanagu please verify.

KoheiKanagu commented 2 years ago

@csells Thank you! That's great.