flutter - Is it necessary to create a new `GoRoute` for each widget which is nested? - Stack Overflow

admin2025-04-17  4

Could you please to explain if we need to create a new GoRoute for each new navigation item?

Let's say I have a bottom navigation where I use GoRouter with StatefulShellRoute with major routes like

Dashboard * Users * Accounts

Let's say the user taps on Accounts (=/accounts), then he taps on item and goes deeper to AccountDetailView (=/accounts/1) which contains a button Edit which should direct user to AccountEditView (=/accounts/1/edit). The edit widget can navigate to new routes AccountEditApiKey (=/accounts/1/edit/api) and AccountEditDescription (=/accounts/1/edit/description).

And question is should we create the new GoRoute for each navigation route?

GoRoute(
  path: `/accounts`,
  builder: (...) => Accounts(),
  routes: [
    GoRoute(
      path: `:id`,
      builder: (...) => AccountDetailView(),
      routes: [
        GoRoute(
          path: `edit`,
          builder: (...) => AccountEditView(),
          routes: [
            GoRoute(
              path: `api`,
              builder: (...) => AccountEditApiKeyView(),
              routes: [
              ],
            ),
            GoRoute(
              path: `description`,
              builder: (...) => AccountEditDescriptionView(),
              routes: [
              ],
            ),
            ... potentially other screens
          ],
        ),
      ],
    ),
  ]
),
// other routes for entities

But if I have dozens entities which may have many nested navigation then how big my routing table becomes?

Is it possible to use navigation 1.0 Navigator.push(context, MaterrialPageRoute(...)) and Navigator.pop for navigation items like AccountEditApiKeyView and AccountEditDescriptionView? And how this will work with route restoration?

转载请注明原文地址:http://www.anycun.com/QandA/1744867214a88741.html