-
-
Notifications
You must be signed in to change notification settings - Fork 410
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
RouteGuard not working with auto tabs routes #1278
Comments
can you provide the sample code to reproduce the bug? The issue written like this is not workable 😔 |
I have here 4 tabs routes with part 'app_router.gr.dart';
@MaterialAutoRouter(
replaceInRouteName: 'Page,Route',
routes: <AutoRoute>[
AutoRoute(
page: HomePage,
initial: true,
children: [
AutoRoute(
page: LandingPage,
initial: true,
maintainState: true,
),
AutoRoute(
page: SchoolsListingPage,
maintainState: true,
),
AutoRoute(
page: NotificationsPage,
maintainState: true,
guards: [AuthGuard],
),
AutoRoute(
page: NavigationMenuPage,
maintainState: true,
),
],
),
AutoRoute(
page: AuthPage,
),
],
)
class AppRouter extends _$AppRouter {
AppRouter() : super(authGuard: AuthGuard());
static AppRouter get i => sl();
}
class AuthGuard extends AutoRouteGuard {
@override
void onNavigation(NavigationResolver resolver, StackRouter router) async {
if (AuthHelper.isAuthenticated) {
resolver.next(true);
} else {
await router.push(AuthRoute());
if (AuthHelper.isAuthenticated) {
resolver.next(true);
}
}
}
}
return AutoTabsRouter(
routes: [
LandingRoute(),
SchoolsListingRoute(),
NotificationsRoute(),
NavigationMenuRoute(),
],
builder: (context, child, animation) {
final tabsRouter = AutoTabsRouter.of(context);
return Scaffold(
body: FadeTransition(
opacity: animation,
child: child,
),
bottomNavigationBar: BottomNavigationBar(
onTap: tabsRouter.setActiveIndex,
currentIndex: tabsRouter.activeIndex,
items: [
BottomNavigationBarItem(icon: Assets.icons.homeSvg.svg(), label: "الرئيسية"),
BottomNavigationBarItem(icon: Assets.icons.gridSvg.svg(), label: "بحث المدارس"),
BottomNavigationBarItem(icon: Assets.icons.gridSvg.svg(), label: "الاشعارات"),
BottomNavigationBarItem(icon: Assets.icons.nav.svg(), label: "القائمة"),
],
),
);
},
); |
@KernelPanic92 Sample code above to reproduce the issue |
Support please @KernelPanic92 |
@AlaaEldeenYsr AutoRouteGuard does not work with tabs yet, I'm considering working on it in the couple next days. |
@Milad-Akarie pls! here same issue |
facing same issue |
Same issiuuu!! |
@Milad-Akarie any workarounds/alternatives that we can use to get around this issue? If you could share any article that'd help greatly :) Also, this library is amazing so far, thanks for the hard work :) |
I was just gonna post a reproduction of this issue. Very confusing that the feature works with |
@moneer-muntazah @TerenceLimjc guarding tab routes is not that simple especially tab routes that use pageView or tabView, in the these views routes are already added to the stack. |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions |
Will v6 fix that issue? |
Yes, it doesn't work because it's just a switcher inside. This will never work in current realization because switching pages without a router. |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions |
Is there any progress on this? @Milad-Akarie |
Any progress on this |
@adar2378 @CoderJerry this is not a bug, guarding tabs is not supported. |
@AlaaEldeenYsr This management doesn't make much sense from a functional standpoint: why give the user the ability to navigate to that element and then penalize them as soon as they do? A good interface should never allow the user to make a mistake.
|
@Milad-Akarie I think maybe we should support it. Because reevaluate does not work on tab router. I have this use case
Do you recommend any other to take user to login page when there were logged out after the HomeTabRouter was pushed? My router setup looks like this AutoRoute(
path: '/login',
page: LoginRouter.page,
children: loginRoutes,
),
AutoRoute(
page: HomeTabRouter.page,
path: '/',
guards: [
if (accountsUsersDataBloc != null)
UserRegistrationGuard(accountsUsersDataBloc),
],
children: [
AutoRoute(
page: HomeTab.page,
path: 'home',
initial: true,
),
AutoRoute(
page: EmptyTab.page,
path: 'empty',
),
AutoRoute(
path: 'settings',
page: SettingsTab.page,
),
],
), |
What about get all these RouteMatch classes void setupRoutes(List<PageRouteInfo> routes) {
final routesToPush = _matchAllOrReportFailure(routes)!; //<------ get all these RouteMatch instances
if (_routeData.hasPendingChildren) {
final preMatchedRoute = _routeData.pendingChildren.last;
final correspondingRouteIndex = routesToPush.indexWhere(
(r) => r.key == preMatchedRoute.key,
);
if (correspondingRouteIndex != -1) {
routesToPush[correspondingRouteIndex] = preMatchedRoute;
_previousIndex = _activeIndex;
_activeIndex = correspondingRouteIndex;
}
}
if (routesToPush.isNotEmpty) {
_pushAll(routesToPush);
}
_routeData.pendingChildren.clear();
} Then in void setActiveIndex(int index, {bool notify = true}) async {
assert(index >= 0 && index < _pages.length);
if (_activeIndex != index) {
final match = routesToPush[index]; //<--- all RouteMatch instances we got when setupRoutes
final canNavigate = _canNaviagate(...) //<--- check if we can navigate
if (canNavigate) { //<--- if can navigate we update tab's index
_previousIndex = _activeIndex;
_activeIndex = index;
if (notify) {
notifyAll();
}
}
}
} I do not know whether this approach works well or causes any errors. Just an idea!! |
No description provided.
The text was updated successfully, but these errors were encountered: