颤音:自动安装:RouteGuard在AutotabsScaffold中不工作
我正在尝试为我的autotabsscaffold添加Auth Guard [底部NAV],但它不起作用,它在其他导航页面上工作,而不仅仅是在我的着陆页中[autotabsscaffold |底部的奈斯居住]我在这里错过了什么吗?
使用:auto_route: ^3.2.4
[pub.dev]
return AutoTabsScaffold(
backgroundColor: Theme
.of(context)
.scaffoldBackgroundColor,
routes: const [
HomeRouter(),
CategoryRouter(),
OrderRouter(),
ProfileRoute(),
],
bottomNavigationBuilder: (_, tabsRouter) {return}
班级Auth Guard:
class RouteGuard extends AutoRedirectGuard {
final AuthService authService;
RouteGuard(this.authService) {
authService.addListener(() {
if (!authService.authenticated) {
// should be called when the logic effecting this guard changes
// e.g when the user is no longer authenticated
reevaluate();
}
});
}
@override
void onNavigation(NavigationResolver resolver, StackRouter router) {
if (authService.authenticated) return resolver.next();
router.push(
LoginRoute(
onLoginCallback: (_) {
resolver.next();
router.removeLast();
},
),
);
}
}
Router.DART
@MaterialAutoRouter(
replaceInRouteName: 'Page|Screen,Route',
routes: <AutoRoute>[
AutoRoute(page: OrderPreviewPage),
AutoRoute(page: AddCardPage,),
AutoRoute(page: PaymentPage,),
AutoRoute(page: SplashPage, initial: true),
AutoRoute(page: MyCartPage,),
AutoRoute(page: IntroPage),
AutoRoute(page: RegisterPage),
AutoRoute(page: ProductDetailPage),
AutoRoute(page: ProductListingPage),
AutoRoute(page: CartSummaryPage,),
AutoRoute(page: LoginPage, path: 'login'), //name: 'LoginRoute'
AutoRoute(
initial: true,
page: LandingPage,
path: 'landing',
children: [
AutoRoute(
path: '',
name: 'homeRouter',
page: HomePage,
),
AutoRoute(
path: 'category',
name: 'categoryRouter',
page: CategoryPage,
),
AutoRoute(
path: 'orders',
name: 'orderRouter',
page: OrdersPage,
),
AutoRoute(
path: 'profile',
guards: [RouteGuard], //<------- here registered router guard but not working in Tabscaffold page
page: ProfilePage,
),
// RedirectRoute(path: '*', redirectTo: ''),
],
),
],
)
试图在底部导航中添加路线防护设备,但它无法正常工作。我在这里想念什么? github问题
I am trying add auth guard for my AutoTabsScaffold [bottom nav] but it's not working, It's working in other navigation pages but not just inside my landing page [where AutoTabsScaffold| Bottom Nav resides] am I missing something here?
using : auto_route: ^3.2.4
[pub.dev]
class LandingPage
return AutoTabsScaffold(
backgroundColor: Theme
.of(context)
.scaffoldBackgroundColor,
routes: const [
HomeRouter(),
CategoryRouter(),
OrderRouter(),
ProfileRoute(),
],
bottomNavigationBuilder: (_, tabsRouter) {return}
class auth guard:
class RouteGuard extends AutoRedirectGuard {
final AuthService authService;
RouteGuard(this.authService) {
authService.addListener(() {
if (!authService.authenticated) {
// should be called when the logic effecting this guard changes
// e.g when the user is no longer authenticated
reevaluate();
}
});
}
@override
void onNavigation(NavigationResolver resolver, StackRouter router) {
if (authService.authenticated) return resolver.next();
router.push(
LoginRoute(
onLoginCallback: (_) {
resolver.next();
router.removeLast();
},
),
);
}
}
router.dart
@MaterialAutoRouter(
replaceInRouteName: 'Page|Screen,Route',
routes: <AutoRoute>[
AutoRoute(page: OrderPreviewPage),
AutoRoute(page: AddCardPage,),
AutoRoute(page: PaymentPage,),
AutoRoute(page: SplashPage, initial: true),
AutoRoute(page: MyCartPage,),
AutoRoute(page: IntroPage),
AutoRoute(page: RegisterPage),
AutoRoute(page: ProductDetailPage),
AutoRoute(page: ProductListingPage),
AutoRoute(page: CartSummaryPage,),
AutoRoute(page: LoginPage, path: 'login'), //name: 'LoginRoute'
AutoRoute(
initial: true,
page: LandingPage,
path: 'landing',
children: [
AutoRoute(
path: '',
name: 'homeRouter',
page: HomePage,
),
AutoRoute(
path: 'category',
name: 'categoryRouter',
page: CategoryPage,
),
AutoRoute(
path: 'orders',
name: 'orderRouter',
page: OrdersPage,
),
AutoRoute(
path: 'profile',
guards: [RouteGuard], //<------- here registered router guard but not working in Tabscaffold page
page: ProfilePage,
),
// RedirectRoute(path: '*', redirectTo: ''),
],
),
],
)
Trying to add a route guard in the bottom navigation but it's not working as I expected. What am I missing here? Github Issue
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我遇到了同样的问题,没有使用
autotabsscaffold
来调用后卫。经过一番调查,事实证明,tabsrouter
中的守卫不是支持I encountered the same problem, guard isn't called with
AutoTabsScaffold
. After some investigation, it turns out that guards inTabsRouter
are not supported ????.我也有类似的结构,对我而言,它可以通过在您案件的嵌套导航顶部添加警卫来工作:
I have a similar structure and for me it work by adding guard at the top of nested navigation in your case in landing :