Based on How can I persist sibling ui-views when changing state?, I try to keep the content view unchanged when I change the main navigation. (plunker).
angular.module('MyApp', [
'ui.router'
])
.config(function($stateProvider, $urlRouterProvider) {
$urlRouterProvider.otherwise('/');
$stateProvider
.state('index', {
url: '/',
views: {
'@': {
templateUrl: 'layout.html'
},
'mainNav@index': {
template: '<a ui-sref="Main3">Main3 - with sub</a><br />'
+ '<a ui-sref="Main4">Main4 - with sub</a>'
},
'subNav@index' : {
template: '<p>This is the sub navigation</p>'
},
'content@index': {
template: '<p>Content shared for MAINs</p>'
}
}
})
.state('Main3', {
parent: 'index',
url: '/Main3',
views: {
/*'mainNav': {
},*/
'subNav': {
template: '<a ui-sref="Main3.Sub1">Main3.Sub1</a><br />'
+ '<a ui-sref="Main3.Sub2">Main3.Sub2</a>'
}
}
})
.state('Main4', {
parent: 'index',
url: '/Main4',
views: {
'subNav': {
template: '<a ui-sref="Main4.Sub1">Main4.Sub1</a><br />'
+ '<a ui-sref="Main4.Sub2">Main4.Sub2</a>'
}
}
})
.state('Main3.Sub1', {
url: '/Sub1',
views: { 'content@index': { template: 'Content of Main3.Sub1' } }
})
.state('Main3.Sub2', {
url: '/Sub2',
views: { 'content@index': { template: 'Content of Main3.Sub2' } }
})
.state('Main4.Sub1', {
url: '/Sub1',
views: { 'content@index': { template: 'Content of Main4.Sub1' } }
})
.state('Main4.Sub2', {
url: '/Sub2',
views: { 'content@index': { template: 'Content of Main4.Sub2' } }
})
});
I found also this (Persist state when changing to another state), but I can't figure out how to persist not only the state, but also the view.
