-
Notifications
You must be signed in to change notification settings - Fork 270
Description
During browsing, the times when fromModular is being set to true are when iterations occur through devTools via the select widget mode, or the back or forward button in the browser is pressed.
The currentConfiguration method is responsible for setting the browser's history, and if it is overwritten, it is the one who maintains the information to rebuild paths and make the setRestoredRoutePath work.
To prevent all pages from being overwritten on the web, setRestoredRoutePath needs to be implemented.
One simple solution is to remove this part of the code:
modular/flutter_modular/lib/src/presenters/navigation/modular_router_delegate.dart
Lines 124 to 137 in 9e195cc
/// The `fromModular` flag prevents all pages in `_pages` from being replaced | |
/// when navigating with the browser's back button | |
/// | |
_lastPageModule.completePop(null); | |
removeInject(_lastPageModule.router.path!); | |
for (var r in _lastPageModule.router.routerOutlet) { | |
removeInject(r.path!); | |
} | |
_pages.remove(_lastPageModule); | |
_pages.add(page); | |
} | |
} |
Another one is to make the currentConfiguration to return null if the code is in Web mode, but this method will prevent the browser to keep the navigation history and the back and foward keys work.
@override
ModularRoute? get currentConfiguration {
if (kIsWeb) {
return null;
}
return _pages.isEmpty ? null : _pages.last.router;
}