Skip to content

How to get current route within resolve function? #3273

Closed
@geoidesic

Description

@geoidesic

I have a service which checks whether the current user has access to the route.
I would like that service to be called as part of the resolve, so that the view never loads if the user should not have access. However, within the resolve function the $state dependency does not yet contain the actual state of the router.

.state('home', {
            url: '/home',
            templateUrl: 'app/home.html',
            controller: 'HomeController',
            controllerAs: 'main',
            resolve:{
                    allowed: function(auth, $state){
                       return auth.isAllowed($state.current.name);
                    }
             },
          })

... however $state.current.name is empty at the point which it is used. How can I pass the state's name (i.e. "home")?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions