Skip to content

[go_router] ShellRoute should allow child ShellRoute instances #111981

@johnpryan

Description

@johnpryan

In order to update the navigation_and_routing sample, we need to place a ShellRoute within another ShellRoute. The route config should be something like this (I took out the builders out for brevity):

    return MaterialApp.router(
      routerConfig: GoRouter(
        initialLocation: '/books/popular',
        routes: [
          ShellRoute(
            routes: [
              ShellRoute(
                navigatorKey: booksNavigatorKey,
                routes: [
                  GoRoute(
                    path: '/books/popular',
                    routes: [
                      GoRoute(
                        parentNavigatorKey: booksNavigatorKey,
                        path: 'book/:bookId',
                      ),
                    ],
                  ),
                  GoRoute(
                    path: '/books/new',
                    routes: /* ... */
                  ),
                  GoRoute(
                    path: '/books/all',
                    routes: /* ... */
                  ),
                ],
              ),
              GoRoute(
                path: '/authors',
              ),
              GoRoute(
                path: '/settings',
              ),
            ],
          ),
          GoRoute(
            path: '/signin',
          ),
        ],
      ),
    );

But the ShellRoute constructor is asserting that it's children are instances of GoRoute, but conceptually it should be OK to place a ShellRoute within another, otherwise, there's no way to display a nested TabBar within a Scaffold with a BottomNavigationBar, for example:

Screen Shot 2022-09-20 at 9 11 02 AM

Metadata

Metadata

Assignees

No one assigned

    Labels

    p: go_routerThe go_router packagepackageflutter/packages repository. See also p: labels.

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions