Angular 2 router.navigate

前端 未结 2 1115
清歌不尽
清歌不尽 2020-12-07 23:57

I\'m trying to navigate to a route in Angular 2 with a mix of route and query parameters.

Here is an example route where the route is the last part of the path:

2条回答
  •  不知归路
    2020-12-08 00:49

    import { ActivatedRoute } from '@angular/router';
    
    export class ClassName {
      
      private router = ActivatedRoute;
    
        constructor(r: ActivatedRoute) {
            this.router =r;
        }
    
    onSuccess() {
         this.router.navigate(['/user_invitation'],
             {queryParams: {email: loginEmail, code: userCode}});
    }
    
    }
    
    
    Get this values:
    ---------------
    
    ngOnInit() {
        this.route
            .queryParams
            .subscribe(params => {
                let code = params['code'];
                let userEmail = params['email'];
            });
    }

    Ref: https://angular.io/docs/ts/latest/api/router/index/NavigationExtras-interface.html

提交回复
热议问题