This repository was archived by the owner on Feb 22, 2018. It is now read-only.
This repository was archived by the owner on Feb 22, 2018. It is now read-only.
history.pushState + RoutePreEnterEvent.allowEnter(false) = infinite redirect loop on back button #1585
Open
Description
Hi,
The problem seems to be the same than this one in angularjs : angular/angular.js#3924
In my app I need to have 2 nested views that change their content depending on the url. Since AngularDart only support one ng-view, I created a nested component that changes its content when it receives an event.
ng-view
---------------------------
| ------------------ |
| |nested-component| |
| | | |
| |________________| |
|__________________________|
When I want to just change the nested component view, I use the RoutePreEnterEvent to prevent angulardart from changing the view and I send and event to the nested component to change its content
This event is thrown in the router :
'settings': ngRoute(
path: '/settings',
// We don't want to change the ng-view here, but juste the nested component
// We use the preEnter event to prevent angulardart from reloading the view
preEnter: (RoutePreEnterEvent e) => dynView(e, 'settings-page', 'settings')),
[...]
dynView(RoutePreEnterEvent e, String elementName, String path) {
// prevent angulardart from reloading the view
e.allowEnter(new Future<bool>.value(false));
// Update the url without reloading the view
window.history.pushState(null, "title", path);
// Throw an event catched by the nested component that will update its content
_scope.rootScope.broadcast('path-changed', [elementName]);
}
This solution works well, but when I use the back button, the browser enters in an infinite loop in which it refreshes the previous view, and I can't manage to stop it..