switchToFeature static method
void
switchToFeature(
- GoRouter router,
- NavigationStorage storage, {
- required String featureKey,
- required String defaultPath,
- String? currentFeatureKey,
Switches to featureKey, saving the current URI under
currentFeatureKey (if given) and restoring featureKey's previously
saved URI, or defaultPath if it has none.
Implementation
static void switchToFeature(
GoRouter router,
NavigationStorage storage, {
required String featureKey,
required String defaultPath,
String? currentFeatureKey,
}) {
final currentUri = router.routerDelegate.currentConfiguration.uri;
storage.clearAllModalCompleters();
if (currentFeatureKey != null && currentFeatureKey != featureKey) {
final fullUri = currentUri.toString();
storage.featurePaths[currentFeatureKey] = fullUri;
}
final savedUri = storage.featurePaths[featureKey];
final targetPath = savedUri ?? defaultPath;
try {
router.go(targetPath);
} catch (e) {
debugPrint('[NavigationUtils] Error navigating to $targetPath: $e');
rethrow;
}
}