Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

How to associate custom metadata with a route if nextRoute.$$route is unavailable #2640

Closed
fnakstad opened this issue May 11, 2013 · 4 comments

Comments

@fnakstad
Copy link

Hello!
I recently tried to find a way of restricting access to some of my routes only to users who are logged in. In doing so I am attaching a custom property to each of my routes which indicates what access level it has. Furthermore, I have a $routeChangeStart handler which inspects this value through nextRoute.$$route, and then performs some logic to admit or forbid access. You can see a full example at fnakstad/angular-client-side-auth.

However, I discovered through issue #1907 that there are plans to remove this property completely, which would render my solution useless. So, I'm wondering if there are any other ways to associate your own metadata with a route and then read it out in the $routeChangeStart handler? Or any plans to implement that kind of functionality?

@lgalfaso
Copy link
Contributor

Hi,
For questions on how to use Angular, please us the mailing list https://groups.google.com/forum/?fromgroups#!forum/angular
BTW, if you look at #1907 you will find the answer to what you are looking for, i.e. next and current are the routes

@fnakstad
Copy link
Author

Hey and thanks for the input,
I'm aware that I can get most route information I need by simply looking at next, but any custom properties I might attach to my routes will be stripped away. Here's an example...

$routeProvider.when('/admin', {
        templateUrl:    'partials/admin',
        controller:     AdminCtrl,
        access:         access.admin
});

Here I create a route where I have a custom property access associated with the route. However, while I am able to retrieve this custom property from next.$$route, it seems to be stripped away from the plain next property.

I've been looking at the documentation, and there doesn't seem to be a way of retrieving custom properties you set on your routes. I thought this issue went beyond simply how Angular works as of today, which is why I posted it here.

@lgalfaso
Copy link
Contributor

Do not know what to tell you without doing a closer look at your code, but I am sure that next has all the custom properties as I use this extensively in the form of

module.run(['$rootScope', function ($rootScope) {
  $rootScope.$on('$routeChangeStart', function (event, next, current) {
    if (next && next.foo) {
      [...]
    }
  });
});

@fnakstad
Copy link
Author

Oh shit. Seems you are right. They didn't show up when inspecting in Chrome Dev Tools. Thanks for you help!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants