Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unexpected behavior with AutoRoute or RedirectRoute when handling multiple tabs of the same type #2056

Open
SERDUN opened this issue Sep 11, 2024 · 0 comments

Comments

@SERDUN
Copy link

SERDUN commented Sep 11, 2024

I've encountered an issue with the inability to correctly handle the initial setting in AutoRoute or:

RedirectRoute(
  path: '',
  redirectTo: bottomMenuFlavorManager.getRedirectTo(),
),

when managing multiple tabs of the same type in the navigation tree.

In my case, I have n tabs with WebView components where the structure is identical, but only the URL changes. When more than one instance of EmbeddedScreenPageRoute exists, the redirect no longer functions as expected. This seems to be due to the use of Map<String, AutoRoute>{} in the RouteCollection.

Here’s a simplified version of my routing setup:

AutoRoute.guarded(
  page: MainShellRoute.page,
  onNavigation: onMainShellRouteGuardNavigation,
  path: 'main',
  children: [
    AutoRoute(
      page: MainScreenPageRoute.page,
      path: '',
      children: [
        RedirectRoute(
          path: '',
          redirectTo: bottomMenuFlavorManager.getRedirectTo(),
        ),
        AutoRoute(
          page: KeypadScreenPageRoute.page,
          path: bottomMenuFlavorManager.getFlavorPathIfExists(MainFlavorType.keypad),
        ),
        ...bottomMenuFlavorManager.getEmbeddedFlavors().map((flavor) {
          return AutoRoute(
            usesPathAsKey: true,
            path: flavor.path,
            page: EmbeddedScreenPageRoute.page,
          );
        }),
      ],
    ),
  ],
),

The paths would look like:

embedded/1
keypad
embedded/2
embedded/3

Additionally, I’m using AutoTabsRouter to manage the tabs, which is configured as follows:

final autoTabsRouter = AutoTabsRouter(
  routes: _getRoutes(),
  builder: (context, child) {
    return Scaffold(
      body: child,
    );
  },
);

List<PageRouteInfo> _getRoutes() {
  return bottomMenuFlavorManager.flavors.map<PageRouteInfo<dynamic>>((flavor) {
    switch (flavor.type) {
      case MainFlavorType.keypad:
        return const KeypadScreenPageRoute();
      case MainFlavorType.embedded:
        return EmbeddedScreenPageRoute(id: 'Tab ${flavor.path}');
      default:
        throw Exception('Unknown flavor type');
    }
  }).toList();
}

Could you provide guidance on an alternative approach to achieve this behavior? Or would this require a change in the plugin itself?

Thanks in advance!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant