Skip to content

canActivate called before init #159

@jdonnal-sp-embedded

Description

@jdonnal-sp-embedded

After upgrading to @angular/core 2.4.8, @angular/router 3.4.8 the angular2-token Route Guards stop working. It looks like the router is checking the canActivate parameter before the app component calls init on the angular2-token service.

route declaration:

const routes: Routes = [
  {
    path: '',
    redirectTo: 'home',
    pathMatch: 'full',
    canActivate: [Angular2TokenService]
  },

app component:

constructor(
    private tokenService: Angular2TokenService,
  ) {    
    //configure angular2-token
    tokenService.init({
      apiPath: 'http://localhost:3000',
      //... more parameters
    })
  }

The page fails to load when it hits the following line of canActivate:

if (this._options.signInStoredUrlStorageKey)

with this._options is undefined. This is because init has not been called yet.

This might be a side effect of #14327

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions