2016-04-16 8 views
10

このURL構造体(私はコントロールがありません)を指定すると、どのようにしてAngular2を使ってハッシュフラグメントを取得できますか?URL2からのハッシュフラグメントを取得Angular2で

http://your-redirect-uri#access_token=ACCESS-TOKEN

私のルータは、正しいコンポーネントへのルートを行いますが、oauth後のすべてが廃棄を取得し、私はrequest.paramsまたはlocation.pathでハッシュフラグメントを見つけることができません。運命づけられた??

ルータの設定:

@RouteConfig([ 
{path: '/welcome', name: 'Welcome', component: WelcomeComponent, useAsDefault: true}, 
{path: '/landing/oauth', name: 'Landing', component: LandingComponent} // this one 

])

答えて

19

import { ActivatedRoute } from '@angular/router'; 

export class MyComponent { 

    constructor(
    private route: ActivatedRoute, 
) { } 

    myfunction(){ 
    this.route.fragment.subscribe((fragment: string) => { 
     console.log("My hash fragment is here => ", fragment) 
    }) 
    } 
} 
1

私は= tokenresponse_typeでのOAuthサーバーを要求することにより、同じ問題を抱えていた、と誰%REDIRECT_URI%#access_token=:access_token&token_type=:token_type&expires_in=:expires_inにリダイレクトします。

デフォルトでは、サブURLへの直接アクセスはルーティングされません。その場合、%BASE_URL%/landing/oauthLandingComponentコンポーネントにリダイレクトされません。

私はこの構成では、それを固定:まだお探しの方に

import { bootstrap } from '@angular/platform-browser-dynamic'; 
import { provide } from '@angular/core'; 
import { APP_BASE_HREF } from '@angular/common'; 
import { ROUTER_PROVIDERS } from '@angular/router'; 

import { AppComponent } from './components/app/app.component'; 

bootstrap(AppComponent, [ 
    ROUTER_PROVIDERS, 
    provide(APP_BASE_HREF, { useValue: '/' }) // this line 
]); 
関連する問題