Skip to content
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
anthony-foulfoin opened this issue Oct 30, 2014 · 1 comment
Labels

Comments

@anthony-foulfoin
Copy link

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..

@naomiblack
Copy link
Contributor

@pavelgj can you comment on this, and potential effort to address? Could we fix in 1.x?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Development

No branches or pull requests

3 participants