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

Problem with nested named routes #92

Closed andyduke closed 2 years ago

andyduke commented 2 years ago

If a name is specified for a nested route, but do not set it for a parent route, then namedLocation will not find a route by the name of the nested route.

final _router = GoRouter(
  routes: [
    GoRoute(
      name: 'movies', // <- Without it, namedLocation('movie-details') will throw an "unknown route name: 'movie-details'" exception.
      path: '/movies',
      pageBuilder: (context, state) => MaterialPage<void>(
        key: state.pageKey,
        child: const MoviesScreen(),
      ),
      routes: [
        GoRoute(
          name: 'movie-details',
          path: ':id',
          pageBuilder: (context, state) => MaterialPage<void>(
            key: state.pageKey,
            child: const MovieDetailsScreen(),
          ),
        ),
      ],
    ),
  ],
  errorPageBuilder: (context, state) => MaterialPage<void>(
    key: state.pageKey,
    child: ErrorPage(state.error),
  ),
);
csells commented 2 years ago

Good catch! I'll take a look.

csells commented 2 years ago

fixed with v2.1.2. @andyduke can you please verify?

andyduke commented 2 years ago

@csells I confirm that in v2.1.2 named routes work as expected.