I'm have the follow structure:
$routeSegmentProvider
.when('/login', 'login')
.when('/users', 'base.users')
.segment('login', {
templateUrl: '/login/login.html',
controller: 'LoginCtrl',
permissions : {
login: false,
profiles: [profiles.public]
}
})
// Use this for not reload the UI
.segment('base', {
templateUrl: '/base.tpl.html',
controller: 'UIBaseCtrl',
permissions : {
login: true,
profiles: [profiles.common]
}
})
.within()
.segment('users', {
default: true,
templateUrl: '/users/users.tpl.html',
controller: 'UsersCtrl',
permissions : {
login: true,
profiles: [profiles.admin]
}
})
In my app.run:
$rootScope.$on("routeSegmentChange", function(event, route) {
console.log(route);
In tests, I found a error in this follow situation:
- /login: route, at index 0 => OK
- /users: route => OK
- go to segment ui, at index 0
- go to segment ui.users, at index 1
- /login: when I return to /login, are showed 3 route objects
First: an route Obj, at index 0, as name login.
Second: an route Obj, at index 1, segment = null
Third: an route Obj, at index 1, segment = null
The second and third should not appear. This causes an error when trying to check the permissions to try to authenticate the route.
For example, if I use:
console.log(route.segment.name);
The console returns:
- login
- ui
- users
and when back to /login, console show:
- login
- TypeError: Cannot read property 'name' of null
- TypeError: Cannot read property 'name' of null
In one more example, if I use:
console.log($routeSegment);
for same sequence of routes calls, the console show the objects:
- Object {name: "login", $routeParams: Object, chain: Array[1] ...
- Object {name: "ui", $routeParams: Object, chain: Array[1] ...
- Object {name: "ui.users", $routeParams: Object, chain: Array[2] ...
- Object {name: " login.users ", $routeParams: Object, chain: Array[1]
- Object {name: "login", $routeParams: Object, chain: Array[2] ...
- Object {name: "login", $routeParams: Object, chain: Array[1] ...
In this case 4 seems to be an error because login.users segment does not exist.
Someone could give a help?
** I tested when $routeChangeStart, but the $routeSegment is always the previous. **.