3

I tried to use canActivate on ionic2, but it seems to have no effect. I am trying to create an authentication mechanism. The method called on the canActivate is

static requireAuth(): boolean {
    const { auth, router } = AuthRouteHelper;
    console.log('requiring auth');
    if (!auth.authenticated) router.navigate(['/Login']);
    return auth.authenticated;
  }
Arash
  • 11,697
  • 14
  • 54
  • 81

2 Answers2

0

Note for whomever wondering, this feature is not working in ionic2 at this time. You need to find a workaround for this. In my case I check for the login, and redirect based on that.

Arash
  • 11,697
  • 14
  • 54
  • 81
  • hey did you had a look on "onPage*" states of an Ionic Page? Nevertheless do you know how to "resolve" data before rendering of a page occurs? – atx Apr 12 '16 at 11:52
  • Not sure if I understand you, but I use observable/emitters to update the properties of the page after render, which triggers another render, but it is fine. – Arash Apr 12 '16 at 18:10
  • Probably i wasn't clear enough, sorry. I did a writeup: http://stackoverflow.com/questions/36569179/ionic2-equivalent-resolve-canactivate maybe you can have a look and share your thoughts – atx Apr 13 '16 at 06:45
-1

canActivate is not working because ionic used NavController

thelastworm
  • 544
  • 4
  • 14