Angular2 Router - Anyone know how to use canActivate in app.ts so that I can redirect to home page if not logged in
I\'m using typescript and angular 2.
These answers are no longer valid in the RC candidate as of 22/6/16.
There is a lot of talk a new solution for @CanActivate
annotation but you can revert back to using the angular-2/router-deprecated
version in the interim.
If you want to follow the updates to this area if you want to use the newer router implementation please check out these two github issues:
Sorry there is no complete answer right now, if I see any further progress on this I'll update this reply. I'm searching for an elegant solution as well.
For the interim I just used a ngIf='fooObject'
in a div to check for object being used in a child directive is populated/truthy and then render the rest of the components html. It's not ideal but it does work consistently right now. May help you or not depending on your use case. I don't need to redirect, only check my data has resolved for the display of my component.