ルータでクエリパラメータを渡す方法リンク 質問する

ルータでクエリパラメータを渡す方法リンク 質問する

クエリパラメータを渡したいですprop=xxx

これはうまくいかなかった

<a [routerLink]="['/somepath', {queryParams: {prop: 'xxx'}}]">
  Somewhere
</a>

ベストアンサー1

queryParams

queryParamsrouterLink渡すことができる別の入力です

<a [routerLink]="['../']" [queryParams]="{prop: 'xxx'}">Somewhere</a>

fragment

<a [routerLink]="['../']" [queryParams]="{prop: 'xxx'}" [fragment]="yyy">Somewhere</a>

routerLinkActiveOptions

親ルートに設定されているルートのアクティブ クラスも取得するには:

[routerLinkActiveOptions]="{ exact: false }"

this.router.navigate(...)使用するクエリパラメータを渡すには

let navigationExtras: NavigationExtras = {
  queryParams: { 'session_id': sessionId },
  fragment: 'anchor'
};

// Navigate to the login page with extras
this.router.navigate(['/login'], navigationExtras);

参照https://angular.io/guide/router#クエリパラメータとフラグメント

おすすめ記事