How to find out the following state in u-router

I show and hide the modality when the user goes into a certain state ( /login), but I would keep the modal background if the users go to /registerfrom /login.

If the user is in /login, and then goes to /register, I would leave the modem open to log in, and if the user is in /login, and then goes to another page, disappear.

I actually install Angular-ui-router $stateProvideras follows:

app.config(function ($stateProvider, $urlRouterProvider, $locationProvider) {
  $stateProvider
    .state('home', {
      url: "/",
      templateUrl: "templates/home.html",
      controller: 'HomeCtrl'
    })
    .state('login', {
      url: "/login",
      onEnter: function ($stateParams, $state, Modal) {
        // * modalCtrl for Login
        if (window.loginModal) {
          window.loginModal.remove();
          delete window.loginModal;
          Modal.fromTemplateUrl('templates/user/login.html', function (modal) {
            window.loginModal = modal;
            loginModal.show();
          });
        } else {
          Modal.fromTemplateUrl('templates/user/login.html', function (modal) {
            window.loginModal = modal;
            loginModal.show();
          });
        }
      },
      onExit: function ($stateParams, $state) {
        if ( window.loginModal && /* condition like "!nextState.is('register')" */ ) {
          window.loginModal.hide();
        }
      }
    })
    .state('register', {
      url: "/register",
      onEnter: function ($stateParams, $state, Modal, SlideBoxDelegate) {
        // * modalCtrl for Register
        if (window.registerModal) {
          window.registerModal.remove();
          delete window.registerModal;
          Modal.fromTemplateUrl('templates/user/register.html', function (modal) {
            window.registerModal = modal;
            SlideBoxDelegate.update();
            registerModal.show();
          });
        } else {
          Modal.fromTemplateUrl('templates/user/register.html', function (modal) {
            window.registerModal = modal;
            SlideBoxDelegate.update();
            registerModal.show();
          });
        }
      },
      onExit: function ($stateParams, $state) {
        if ( window.registerModal ) {
          window.registerModal.hide();
        }
      }
    })
    .state('not_found', {
      url: "/not_found",
      templateUrl: 'templates/not_found.html',
      controller: 'NotFoundCtrl'
    })
  $urlRouterProvider.otherwise("/not_found");
  $locationProvider.html5Mode(true);
})

Is there any way to install condition like "!nextState.is('register')"?

Thanks for reading:)

+4
source share
2 answers

$stateChangeStart to , onExit, .

, , .

+2

, , $state onExit:

onExit: function ($state) {
  $state.transition.then(toState => {
    if (toState.name === 'nameOfTheWantedNextState') {
      $state.go($state.current, {}, {reload: true});
    }
  })
}

-, , . !

+2

All Articles