Skip to content
This repository has been archived by the owner on May 29, 2019. It is now read-only.

History traversal can still occur while modal is up #2244

Closed
ngoyal opened this issue May 22, 2014 · 3 comments
Closed

History traversal can still occur while modal is up #2244

ngoyal opened this issue May 22, 2014 · 3 comments

Comments

@ngoyal
Copy link

ngoyal commented May 22, 2014

This may be related to #738.

In v 0.11.0 when a modal is up, I am able to have the background page go back a route via keyboard shortcuts (on mac in chrome it is cmd + left arrow). I think history traversal should be prevented in this case if the action ends up being a route within the same SPA.

I should note that I am using angular-ui-router for state routing.

@pkozlowski-opensource
Copy link
Member

@ngoyal we don't have any built-in handling of the location / route change and this is by design. The reason for this is that I've heard people asking one of 2 different behaviours (there are probably other use-cases as well):

  • prevent location / route change when a modal is open
  • close all the open modals when location / route change occurs

As you can see those are 2 contradicting requirements and we don't want to do arbitrary choices in this library.

The good news is that you can easily handle it in your application code using the built-in modalStack service. For example, to prevent route change you could write (warning! non-tested code!):

angular.module('myApp', []).run(function($rootScope, $modalStack){
    $rootScope.on('$locationChangeStart', function(evt) {
      if ($modalStack.top()) {
        evt.preventDefault();
      } 
   });
});   

Would it work for you?

@ngoyal
Copy link
Author

ngoyal commented May 22, 2014

Absolutely that would work. I appreciate the suggested fix and quick response.

@ngoyal ngoyal closed this as completed May 22, 2014
@ngoyal
Copy link
Author

ngoyal commented May 22, 2014

Quick copy/paste fix on the example for those who see this:

angular.module('myApp', []).run(function($rootScope, $modalStack){
    $rootScope.$on('$locationChangeStart', function(evt) {
      if ($modalStack.getTop()) {
        evt.preventDefault();
      } 
   });
}); 

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

No branches or pull requests

2 participants