group method
Group routes
settings
is a function that returns a map of settings.
router
is a function that returns a router.
Example:
group(() {
return {
'prefix': '/auth',
'route_guards': [AuthGuard()]
};
}, (router) {
router.route(AccountPage.path, (_) => AccountPage());
router.route(AccountSettingsPage.path, (_) => AccountSettingsPage());
});
Implementation
group(Map<String, dynamic> Function() settings,
Function(NyRouter router) router) {
NyRouter nyRouter = NyRouter();
router(nyRouter);
List<NyRouteGuard> routeGuards = [];
String? prefix;
PageTransitionType? transition;
PageTransitionSettings? pageTransitionSettings;
Map<String, dynamic> routeConfig = settings();
if (routeConfig.containsKey('route_guards') &&
routeConfig['route_guards'] is List<NyRouteGuard>) {
routeGuards = routeConfig['route_guards'] as List<NyRouteGuard>;
}
if (routeConfig.containsKey('prefix') && routeConfig['prefix'] is String) {
prefix = routeConfig['prefix'] as String;
}
if (routeConfig.containsKey('transition') &&
routeConfig['transition'] is PageTransitionType) {
transition = routeConfig['transition'] as PageTransitionType;
}
if (routeConfig.containsKey('transition_settings') &&
routeConfig['transition_settings'] is PageTransitionSettings) {
pageTransitionSettings =
routeConfig['transition_settings'] as PageTransitionSettings;
}
nyRouter.getRegisteredRoutes().forEach((key, NyRouterRoute route) {
if (routeGuards.isNotEmpty) {
route.addRouteGuards(routeGuards);
}
if (prefix != null) {
NyNavigator.instance.prefixRoutes[key] = prefix;
route.addPrefixToName(prefix);
}
if (transition != null) {
route.transition(transition);
}
if (pageTransitionSettings != null) {
route.pageTransitionSettings = pageTransitionSettings;
}
});
setNyRoutes(nyRouter);
assert(
_routeNameMappings.entries
.where((element) => element.value.getInitialRoute() == true)
.length <=
1,
'Your project has more than one initial route defined, please check your router file.');
}