Milad-Akarie / auto_route_library

Flutter route generator
MIT License
1.52k stars 384 forks source link

Inherited Path Parameters aren't working #1990

Closed geronimol closed 1 week ago

geronimol commented 2 weeks ago

I am using v8.2.0 on Web(Chrome)

I couldn't find a way to navigate to Route3

AutoRoute(path: '/home', page: HomeRoute.page, initial: true),
AutoRoute(path: '/route1', page: Route1.page),
AutoRoute(
  path: '/:id',
  page: Route2.page,
  children: [AutoRoute(path: 'route3', page: Route3.page)],
),

Following docs, I added this to Route3

@RoutePage()
class Page3 extends StatelessWidget {
  const Page3({super.key, @PathParam.inherit('id') required String id});

Tried this from Route2 page

AutoRouter.of(context).push(Route3())

and this

AutoRouter.of(context).pushNamed('route3')

But didn't work. Not sure if #1827 and #1963 are related

jakelaws1 commented 2 weeks ago

I am having the same issue!

Milad-Akarie commented 1 week ago

@geronimol Please make sure you have a proper nested routes setup https://pub.dev/packages/auto_route#nested-navigation Route2 widget must have an AutoRouter Widget to render child routes

geronimol commented 1 week ago

@Milad-Akarie I was looking to Inherited Path Parameters section, but didn't know is that is related to nested navigation, thanks!

I was able to navigate to Route3 by adding this new widget:

@RoutePage()
class Page2Wrapper extends StatelessWidget {
  const Page2Wrapper({super.key});

  @override
  Widget build(BuildContext context) {
    return const AutoRouter();
  }
}

Then changed the routes like so:

AutoRoute(path: '/home', page: HomeRoute.page, initial: true),
AutoRoute(path: '/route1', page: Route1.page),
AutoRoute(
  path: '/:id',
  page: Route2Wrapper.page,
  children: [
    AutoRoute(path: 'route2', page: Route2.page),
    AutoRoute(path: 'route3', page: Route3.page),
  ],
),

Hope this helps @jakelaws1