I am building this route system
var app = angular.module('plunker', ['ui.router']);
app.config(function ($stateProvider, $urlRouterProvider) {
$urlRouterProvider
.when('/admin', '/admin/dashboard')
.when('/user', '/user/dashboard')
.otherwise('/admin/dashboard');
$stateProvider
.state('admin', {
url: '/admin/dashboard',
resolve: {
test: function() {
console.log('called admin');
return;
}
},
views: {
'navigation': {
template: '<div>admin navigation. Go <a ui-sref="admin.link1">link1</a></div>'
},
'content': {
template: '<div>admin dashboard</div>'
}
}
})
.state('admin.link1', { //for some reason admin.link1 does not work but just link1 is OK
url: '/admin/link1',
resolve: {
test: function() {
console.log('admin.link1 called resolve');
return;
}
},
views: {
'navigation': {
template: '<div>admin navigation</div>'
},
'content': {
template: '<div>admin link1</div>'
}
}
})
.state('user', {
url: '/user/dashboard',
views: {
'navigation': {
template: '<div>user navigation</div>'
},
'content': {
template: '<div>user dashboard</div>'
}
}
});
});
The HTML will have navigation
and content
ui-view
in it
<body ng-app="plunker">
<div>
<a ui-sref="admin">Admin</a>
<a ui-sref="user">User</a>
</div>
<div ui-view="navigation"></div>
<div ui-view="content"></div>
</body>
I want to click on link1
and go to admin.link1
state but somehow that is not working.
But if I remove the admin
parent and use link1
only, it works fine.
Code: http://plnkr.co/edit/F7lw58esXz7rWzeo3ER6?p=preview
Preview: http://embed.plnkr.co/F7lw58esXz7rWzeo3ER6/preview
Any clue?
You were almost there, the updated plunker. There is only one change the nested views do have appended sign '@':
The point is hidden in the absolut view naming, an extract:
The working example(s) here or other here
Please, try to read this answer, where I tried deeply describe what is the view naming about.(search for a last section: EXTEND: to give THE answer to a comment)