Angular Ui Router: stop $ state.go to reload the controllers, but change the url

My application uses it $state.gowhen switching between tabs, and this leads to reinitialization of the controllers and variable scope in these controllers, which are updated and cause a memory leak. Is there a way to stop the reinitialization of the controllers, but change the URL when the state changes?

Example below: routes.js in my application.

.state('home', 
{
    abstract    : true,            
    url         : '/home',
    templateUrl : 'scripts/home.html'
})
.state('home.summary', 
{
    url        : '/summary?userId', 
    controller : 'SummaryCtrl',                
    views      : 
    {               
        summary: 
        {
            templateUrl: 'scripts/home/summary.html'
        }
    }
})
.state('home.summary.detail', 
{
    url        : '/detail/:id',
    controller : 'DetailCtrl',                 
    views      : 
    {               
        detail: 
        {
            templateUrl: 'scripts/home/detail.html'
        }
    }
})

How to stop reloading DetailCtrl, but change the URL when you are going to specify home.summary.detail if DetailCtrl is already loaded for a unique id ???

Also tried to execute $ q.reject in resolving the child state, it stops reloading the controllers, but does not change the URL.

reloadOnSearch = false, , URL.

+4
2

$state.transitionTo $state.go . $state.go $state.transitionTo , { location: true, inherit: true, relative: $state.$current, notify: true } . $state.transitionTo location: false . :

$state.go('.detail', {id: newId}) 

 $state.transitionTo ('.detail', {id: newId}, { location: false, inherit: true, relative: $state.$current, notify: true }) 
+4

Source: https://habr.com/ru/post/1538661/


All Articles