0

I'm trying to use angular-ui-router to navigate through states without reloading the controller and view. I.e. if I'm in app.posts and I navigate to app.postId using an href and click back button in the browser, the app.posts view should appear and the state should be as it was before. Currently the state is reloaded as if it was opened for the first time.

Also html5mode is enabled on the $locationProvider.

The states are defined as

app.config(function($stateProvider, $locationProvider) {

$stateProvider
.state('app.home', {
  url: '/home',
  templateUrl: 'js/main/templates/home.html',
  controller: 'HomeCtrl'
})

.state('app.posts', {
  url: '/',
  templateUrl: 'js/PostList/PostList.html',
  controller: 'PostListCtrl',
  deepStateRedirect: true
})
.state('app.postId', {
  url: '/post/:id',
  templateUrl: 'js/Post/Post.html',
  controller: 'PostViewCtrl'
});

$locationProvider.html5Mode({enabled:true, requireBase:false});
shadowcursor
  • 1,174
  • 1
  • 13
  • 19

1 Answers1

1

The only time a controller result does not re-initialize is if you are going back to a parent state.

There's an in-depth conversation about this here: Caching URL view/state with parameters

Community
  • 1
  • 1
David Boskovic
  • 1,469
  • 9
  • 14