I asked a similar case here but then I found out it was not exactly what I wanted to do:
Here is a new version:
HTML
<body ng-app="plunker">
<div>
<a ui-sref="admin">Admin</a>
<a ui-sref="user">User</a>
</div>
<div ui-view></div>
</body>
JS
var app = angular.module('plunker', ['ui.router']);
app.config(function ($stateProvider, $urlRouterProvider) {
$urlRouterProvider
.when('/', '/admin/dashboard')
.when('/admin', '/admin/dashboard')
.when('/user', '/user/dashboard')
.otherwise('/admin/dashboard');
$stateProvider
.state('admin.dashboard', {
url: '/admin/dashboard',
resolve: {
test: function() {
console.log('called admin');
return;
}
},
template: '<div>admin navigation. Go <a ui-sref="admin.link1">link1</a></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;
}
},
template: '<div>admin link1</div>'
})
.state('user', {
url: '/user/dashboard',
template: '<div>user dashboard</div>'
});
});
CODE: http://plnkr.co/edit/NYdWC1j9xskQnY8LjJkZ?p=preview
Requirements
I don't need to render anything for parent routes (
admin
)The default redirect will be
/admin/dashboard
I need the url to be properly structure as child of
/admin
because previous question, it ended up to be/admin/dashboard/admin/link1
I do need
admin
anduser
parents. There is a need for children relationship. This will be used later.
Problems
Right now I cannot show child routes like
admin.dashboard
. It's just blank. How to showdashboard
by default?If I added the lines below to show the
admin
template, even thisui-sref="admin.dashboard"
won't take me to the correctdashboard
child route
javascript
.state('admin', {
url: '/admin',
template: '<div>admin. Go <a ui-sref="admin.dashboard">dashboard</a></div>'
})