Angular 角度6星云6获取组件中的查询参数

Angular 角度6星云6获取组件中的查询参数,angular,authentication,routing,angular-routing,Angular,Authentication,Routing,Angular Routing,我使用Angular 6,ngx管理主题进行身份验证。我想在url中传递重置密码的令牌id,并在重置密码表单中获取该id,以便将其传递给后端服务器。下面是我的app-routing.module.ts文件: { path: 'auth', component: NgxAuthComponent, children: [ { path: '', component: NgxLoginComponent, }, { path: 'request-password'

我使用Angular 6,ngx管理主题进行身份验证。我想在url中传递重置密码的令牌id,并在重置密码表单中获取该id,以便将其传递给后端服务器。下面是我的app-routing.module.ts文件:

{
path: 'auth',
component: NgxAuthComponent,
children: [
  {
    path: '',
    component: NgxLoginComponent,
  },
  {
    path: 'request-password',
    component: NgxRequestPasswordComponent,
  },
  {
    path: 'reset-password/:token',//here i need token
    component: NgxResetPasswordComponent,
  },
下面是NgxResetPasswordComponent文件:

constructor(protected service: NbAuthService,
          @Inject(NB_AUTH_OPTIONS) protected config = {},
          protected router: Router) {

this.redirectDelay = this.getConfigValue('forms.resetPassword.redirectDelay');
this.showMessages = this.getConfigValue('forms.resetPassword.showMessages');
this.provider = this.getConfigValue('forms.resetPassword.provider');

  console.log(this.router.url);//output: /auth/reset-password/dsadasdasfaf

}

我需要从这个URL获取“dsadasdasfaf”并将其传递给表单。

首先导入
activaterout
并初始化它

constructor(private activatedRoute: ActivatedRoute) {}

this.activatedRoute.params.subscribe((params: Params) => {
        let token = params['token'];
        console.log(token);
      });