Page redirect, which prevents $ionicView.afterEnter triggering


#1

When the user views the home page, i’d like to redirect immediately to the introduction page given a certain flag.
The problem is, the “afterEnter” is triggering on the home page despite the introduction page now being visible.

I would like to redirect from home to intro while prevent afterEnter triggering on home.

For an example home page:

$scope.$on('$ionicView.beforeEnter', function () {
   if (goIntro) {
      $state.go("intro");
   } else {
      loadHomePage();
   }
}

$scope.$on('$ionicView.afterEnter', function () {
   console.log("I should not happen! if goIntro == true");
   // I do not want the one-off animation to occur while the intro page is viewed
   // Therefore i do not want this to happen, until we navigate to home after doing the intro
   runComplexAnimation();
}

#2

I found https://github.com/angular-ui/ui-router/wiki/URL-Routing#when-for-redirection
but not sure if it can help in my case. Any hints?

if (boolean) { toToPage} else {continue with current page}


#3

Ended up using:

$rootScope.$on("$locationChangeStart", function (event, next, current) {
                if ($location.path() == '/home') {
                    if (goIntro) {
                        event.preventDefault();
                        $location.path('intro');
                    }
                }
            });