angular-route-segment icon indicating copy to clipboard operation
angular-route-segment copied to clipboard

routeSegmentChange problem

Open drantunes opened this issue 11 years ago • 0 comments

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:

  1. /login: route, at index 0 => OK
  2. /users: route => OK
    • go to segment ui, at index 0
    • go to segment ui.users, at index 1
  3. /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:

  1. login
  2. ui
  3. users and when back to /login, console show:
  4. login
  5. TypeError: Cannot read property 'name' of null
  6. 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:

  1. Object {name: "login", $routeParams: Object, chain: Array[1] ...
  2. Object {name: "ui", $routeParams: Object, chain: Array[1] ...
  3. Object {name: "ui.users", $routeParams: Object, chain: Array[2] ...
  4. Object {name: " login.users ", $routeParams: Object, chain: Array[1]
  5. Object {name: "login", $routeParams: Object, chain: Array[2] ...
  6. 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. **.

drantunes avatar Jul 31 '14 18:07 drantunes