Dynamic routing in AngularJS

1,449 views
Skip to first unread message

Sascha Schiffer

unread,
Aug 7, 2012, 10:56:45 AM8/7/12
to ang...@googlegroups.com
Hi,

I am facing a problem with the routing-provider. As I can say at the moment, it's not possible to alter the routes into the runtime without some hacks, but I gues, I'm just doing something wrong. I load the navigation items from a dynamically generated json(REST). The navigation depends on User-Rights and other stuff.

So my current solution is to declare a variable into the global Scope to exchange the route-provider to a service, which creates the routing at runtime. I don't think, that this is a good solution, so I ask if there is an "best-practice" for this.

What I am doing now:

app.js

var uglyHackedRouteProvider = null; 
[...] 
config(['$routeProvider', function ($routeProvider, $location,$RouteProvider)

 uglyHackedRouteProvider = $routeProvider
 

In services.js

factoryObject.routeProvider = uglyHackedRouteProvider;


Any ideas to solve this a little bit nicer?

Jason Als

unread,
Aug 8, 2012, 7:00:37 AM8/8/12
to ang...@googlegroups.com

Sascha Schiffer

unread,
Aug 8, 2012, 9:27:11 AM8/8/12
to ang...@googlegroups.com
I've read that thread before posting my own. That's not really, what I want, as I have to define the structure of all routes. But I want to be able to define all parts of the routing within the JSON-Files.
This solution is very restrictive, as you have to predefine every possible type of parameter/route.

For now my approach is working, if I reload the current route after the init-stage. But I am still not really happy with it.

Jason Berk

unread,
Sep 6, 2012, 2:51:31 PM9/6/12
to ang...@googlegroups.com
I am in the exact same boat.  I need to create a left nav menu that's built based on the user role in AD.

I've seen some examples that return the menu html from a rest call, but that's really dirty.  The server side should be returning at most, the user role and the view should be create dynamically on the client.

I'm inspecting this: https://github.com/nwinkler/angular-dynamic-routing and will see if it's any cleaner

Jason
Message has been deleted

EdCh

unread,
Oct 2, 2012, 2:38:38 PM10/2/12
to ang...@googlegroups.com
Could you share your experience with the github project since your last post.  I have the same requirement.

I was thinking, the requirement to construct a menu dynamically based on user role is very common in business applications.  The idea of having a JS file itemizing all possible routes on the client concerns me from a security standpoint.

Any further news in this space?

Josh Kurz

unread,
Oct 2, 2012, 4:38:47 PM10/2/12
to ang...@googlegroups.com
What concerns you? The only routes available are the ones you program in to be available at any certain state.

Unless there was a way to manipulate JavaScript variables manually from the client side. If there is then I would like to know. 

Josh Kurz 

--
You received this message because you are subscribed to the Google Groups "AngularJS" group.
To post to this group, send email to ang...@googlegroups.com.
To unsubscribe from this group, send email to angular+u...@googlegroups.com.
Visit this group at http://groups.google.com/group/angular?hl=en.
 
 

EdCh

unread,
Oct 2, 2012, 5:12:42 PM10/2/12
to ang...@googlegroups.com
I guess what concerns me is a snoopy user being able to see what routes exist for users in other roles they're not authorized to access.  It's none of their business.  It bothered me that I was making it too easy to discover these routes.
 
I was thinking that if I redirect to a non-partial page for urls unrelated to my angular module I can use the server-side logic to decide if it's OK to display the page and associated JS files.  I just did a quickie test and this seems to work.  This is probably not fullproof, but it's enough to mitigate my concerns for the moment.  I'm in the middle of reading a book on AJAX security and I guess it's made me a little more paranoid :-)
 
Let me know if you think this approach is not advisable.
 
Reply all
Reply to author
Forward
0 new messages