私は、サードパーティAPIによってangle2アプリケーションに渡されるURLクエリ文字列パラメータを取得するのに苦労しています。 URLが読み取るhttp://example.com?oauth_token=123Angular2コンポーネントルータ:クエリクエリパラメータを取得
コンポーネント内で "oauth_token"の値を取得するにはどうすればよいですか?私は喜んでそれはちょうどクエリ文字列の基本的なルーティングのためのコンポーネントルータを使用しています。私はいくつかの試みを行い、最新の受信コンポーネントは次のようになります
import { Component, OnInit } from '@angular/core';
import { ActivatedRoute } from '@angular/router';
@Component({
template: ''
})
export class TwitterAuthorisedComponent implements OnInit {
private oauth_token:string;
constructor(private route: ActivatedRoute) {}
ngOnInit() {
console.log('the oauth token is');
console.log(this.route.snapshot.params.oauth_token);
}
}
アドバイスをいただければ幸いです。
** UPDATE
私はすべての私のルートをコメントアウトした場合、クエリパラメータは、しかし、私は、クエリパラメータは、ページの読み込みに削除された経路を含めた瞬間に固執します。以下は私のルートのストリップダウンコピー私はルートクエリのparamsスティックを削除する場合は1つのルート
import {NavigationComponent} from "./navigation/components/navigation.component";
import {TwitterAuthorisedComponent} from "./twitter/components/twitter-authorised.component";
import { provideRouter, RouterConfig } from '@angular/router';
export const routes: RouterConfig = [
{ path: '', component: TwitterAuthorisedComponent }
];
export const appRouterProviders = [
provideRouter(routes)
];
を持つファイルです。何かアドバイス?
ご意見ありがとうございます。私はあなたの解決策を試しましたが、あなたが正しいと確信していますが、それは私のために働いていません。私は、クエリ文字列でアプリケーションを読み込むと気づいた?foo = barページロード時に失われます。瞬間ページはURLをhttp:// localhost:8000 /#/に変換し、AppComponentからURLを取得することもできません。任意のクエリ文字列を削除するURLの変更は正常ですか? – prime
私はそれが普通だとは思わない。クエリパラメータは固執するはずです。途中にリダイレクトがある可能性があります。 – yarons