1

I user angular2 rc.3 、router-3.0.0-alpha.8 and OAuth2 ,

I use OAuth2 ,so after logged in ,How to angular2 front carry token header to navigate other component each time

const APP_ROUTES:RouterConfig = [
   {path: '', component: HomeComponent},
   {path: 'admin', component: AdminComponent},
   {path: 'user', component: UserComponent}

];

e.g. when i want to navigate to the protected 'admin' page , using this.router.navigate(['/admin']);

Kery Hu
  • 5,626
  • 11
  • 34
  • 51
  • What do you mean by "add the access-token to router-config" or "add access-token in the header"? – Günter Zöchbauer Jun 30 '16 at 10:07
  • assume **'admin'** page is a protected page , navigate to it needs**'access-token'** header , How can i set it in the router config – Kery Hu Jun 30 '16 at 10:29
  • See this answer http://stackoverflow.com/questions/38096475/angular2-canactivate-from-beta-to-current-rc3/38096551#38096551 – Günter Zöchbauer Jun 30 '16 at 10:31
  • but above implemts didn't add the access-token to the request head . so if refresh the page ,it will respond 401 – Kery Hu Jun 30 '16 at 11:51
  • No idea what request you are talking about. – Günter Zöchbauer Jun 30 '16 at 12:12
  • so the `templateUrl` is pointing at a page/partial page from an asp.net mvc controller / php / some sort of protected directory which requires some sort of authorization to be available? – Matthew Jun 30 '16 at 14:03
  • if yes. The second solution Extending `BaseRequestOptions` http://stackoverflow.com/questions/34464108/angular2-set-headers-for-every-request might be what you are after. I have not tried it and not sure if the cache provider gets it this way. – Matthew Jun 30 '16 at 14:08
  • I use OAuth2 ,so after logged in ,front needs carrying token header to navigate other component each time . – Kery Hu Jun 30 '16 at 14:08
  • @Matthew i use `class MyRequestOptions extends BaseRequestOptions` but when router navigate to protected component , token didn't be added . – Kery Hu Jun 30 '16 at 14:26
  • Did you include (in bootstrap): `provide(RequestOptions, { useClass: MyRequestOptions })` ? If that didnt work it was a interesting guess. – Matthew Jul 01 '16 at 08:30

0 Answers0