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
441 stars 96 forks source link

Using pushNamed directly to a named nested route will result in missing params in the GoRouterState #315

Closed baueric closed 2 years ago

baueric commented 2 years ago

Please let me know if I'm organizing my routes wrong but it seems like this should work. If you have these routes:

GoRoute(
  name: 'family',
  path: '/family/:familyId',
  builder: (context, state) => FamilyPage(familyId: state.params['familyId']),
},
GoRoute(
  name: 'person',
  path: '/person/:personId',
  builder: (context, state) => PersonPage(personId: state.params['personId']),
  routes: [
    GoRoute(
      name: 'personMore'
      path: 'more-person-stuff'
      builder: (context, state) => PersonMorePage(personId: state.params['personId']),
    )
  ]
)

Here is what I'm experiencing:

For situation 3 I'm seeing the builder's state.params has value: {'familyId': 'family1'} even though the state.location is '/person/person1/more-person-stuff'. So it's odd to me that the location string is correct but the params is missing the personId value. Any ideas?

And thank you for creating this amazing router!

csells commented 2 years ago

What you're doing should work just fine. Can you post a minimal repro?

If you're trying to build a stack of family|person|personMore, why not arrange your routes like this:

GoRoute(
  name: 'family',
  path: '/family/:familyId',
  builder: (context, state) => FamilyPage(familyId: state.params['familyId']),
  routes: [
      GoRoute(
        name: 'person',
        path: '/person/:personId',
        builder: (context, state) => PersonPage(personId: state.params['personId']),
        routes: [
          GoRoute(
            name: 'personMore'
            path: 'more-person-stuff'
            builder: (context, state) => PersonMorePage(personId: state.params['personId']),
          )
        ]
      )
  ]
)

Now you can just goNamed('family'), goNamed('person') and goNamed('personMore') and you'll get a stack of one, two or three pages as appropriate.

baueric commented 2 years ago

I think your example would work but I should have used different example objects than family and person because it's important the routes are not nested. I also want to use a push action to add the nested route to my current stack and not a go action. I will try to add a full example in the next day or two.

csells commented 2 years ago

closing due to lack of customer input. feel free to reopen if you have a minimal repro of this issue.