How to pass query parameters with a routerLink

前端 未结 1 1972
情话喂你
情话喂你 2020-11-30 22:55

I want to pass a query parameter prop=xxx.

This didn\'t work

Som         


        
相关标签:
1条回答
  • 2020-11-30 23:19

    queryParams

    queryParams is another input of routerLink where they can be passed like

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

    fragment

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

    routerLinkActiveOptions

    To also get routes active class set on parent routes:

    [routerLinkActiveOptions]="{ exact: false }"
    

    To pass query parameters to this.router.navigate(...) use

    let navigationExtras: NavigationExtras = {
      queryParams: { 'session_id': sessionId },
      fragment: 'anchor'
    };
    
    // Navigate to the login page with extras
    this.router.navigate(['/login'], navigationExtras);
    

    See also https://angular.io/guide/router#query-parameters-and-fragments

    0 讨论(0)
提交回复
热议问题