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

How to redirect to a children of a AutoTabsRouter #2104

Open
giordy16 opened this issue Dec 5, 2024 · 0 comments
Open

How to redirect to a children of a AutoTabsRouter #2104

giordy16 opened this issue Dec 5, 2024 · 0 comments

Comments

@giordy16
Copy link

giordy16 commented Dec 5, 2024

I need to redirect the users to SettingsRoute2 if they haven't imported some data, which is the 4th tab of a AutoTabsRouter. How can I do it? This is the routing class, but it's not working like that

@AutoRouterConfig(replaceInRouteName: 'Screen|Page,Route')
class AppRouter extends RootStackRouter {
  @override
  RouteType get defaultRouteType => const RouteType.material();

  @override
  List<AutoRoute> get routes => [
        AutoRoute(
          page: HomeNavigationRoute.page,
          initial: true,
          guards: [EmptyMasterDataGuard()],
          children: [
            AutoRoute(page: LocalAuditListRoute2.page, initial: true),
            AutoRoute(page: RemoteAuditListRoute.page),
            AutoRoute(page: TempRoute.page),
            AutoRoute(page: SettingsRoute2.page),
          ],
        ),
      ];
}

class EmptyMasterDataGuard extends AutoRouteGuard {
  @override
  void onNavigation(NavigationResolver resolver, StackRouter router) {
    bool emptyApp = !(GetIt.I<Settings>().isCompleted ?? false);
    if (emptyApp) {
      resolver.redirect(SettingsRoute2());
    } else {
      resolver.next(true);
    }
  }
}

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