Prevent parent controller reboot in ui-router

I have a problem with nested views in ui-router.

My layout:

site.search
-----------------
site.search.runs
-----------------
site.search.runs.scheme
-----------------
site.search.runs.scheme.payment
-----------------

I do not want to change the URL, so I use $state.go('', {}, {location:false});  I also use $stage.go('^'...)to return to the parent.

But when I click the back button on site.search.runs.scheme.payment or site.search.runs.scheme, the controller also reboots (I do not use {reload: true}).
 How to prevent rebooting of the parent top-level controller?
 I found a problem like my https://github.com/angular-ui/ui-router/issues/2096
 Can anyone help me?

My configuration

$stateProvider
        .state('site', {
            abstract: true,
            url: '',
            template: '<ui-view/>'
        })
        .state('site.search', {
            url: '',
            parent: 'site',
            controller: 'SearchController',
            controllerAs: 'search',
            templateUrl: 'js/search/search.tpl.html'
        })
        .state('site.search.runs', {
            url: '',
            parent: 'site.search',
            params: {back: false, timestamp: 0, search: {}},
            controller: 'RunsController as runsCtrl',
            templateUrl: 'js/runs/runs.tpl.html'
        })
        .state('site.search.runs.scheme', {
            url: '',
            parent: 'site.search.runs',
            params: {back: false, run: ''},
            controller: 'SchemeController as schemeCtrl',
            templateUrl: 'js/scheme/scheme.tpl.html'
        })
        .state('site.search.runs.scheme.payment', {
            url: '',
            parent: 'site.search.runs.scheme',
            params: {back: false},
            controller: 'PaymentController as payCtrl',
            templateUrl: 'js/payment/liqpay/payment.tpl.html'
        })
});

$state.go('^', {: true}, {location: false, inherit: false});

+4
2

, , if - ( , , , ):

// make sure you inject $state
// and put the if statement inside the main function of your controller

function RunsController($state) {
    // var will return something like: site.search.runs.scheme
    var currentState = $state.current.name;

    if (currentState === 'site.search.runs') {
        // in here put the code that would normally be in this controller for site.search.runs
    }

}
0

, $state.go().

notify: false $state.go('^', {back: true}, {location: false, inherit: false, notify: false});

state.go , , $state.transitionTo(), :

$rootScope.$on('$stateChangeStart', function(event, toState) {
    $state.transitionTo('login');
}

,

$state.transitionTo('^', $stateParams, {
            reload: false, inherit: false, notify: false
        });

, , , . $state. $Current, "", , .

0

All Articles