[angular2] @CanActivate versus routerOnActivate

312 views
Skip to first unread message

michael corbridge

unread,
Jan 15, 2016, 7:14:39 PM1/15/16
to AngularJS
I have built some basic authentication security into angular2 app using routes.  
From a login page I set a boolean in a class that is injected into the routed components. 
When the route changes, the routerOnActivate method in the routed component looks at that class for a isLoggedIn boolean that will route the user back to the login view if false.
It works <happy-sounds>great </happy-sounds>, but it seems a waste not to use the @CanActivate decorator.
Anyone out there know how to inject that login class into @CanActivate?

Eric Martinez

unread,
Jan 15, 2016, 7:51:29 PM1/15/16
to AngularJS
Michael,

so far is not possible, but there are workarounds. Check out this issue, it's pretty interesting (specially @brandonroberts comments).

michael corbridge

unread,
Jan 15, 2016, 9:49:57 PM1/15/16
to AngularJS
thanks Eric - hopefully Brian Ford adds DI to @CanActivate
Reply all
Reply to author
Forward
0 new messages