Angular 2 中参数 404 中的电子邮件地址

Email Address in params 404s in Angular 2

我有几个 URL 有共同的关系: http://localhost:3000/account/changeforgottenpassword

(200OK,通过) http://localhost:3000/account/changeforgottenpassword/testexample/75c09b18-6090-44df-a18d-d1fe06ab1cde

(200OK,通过) http://localhost:3000/account/changeforgottenpassword/testexample2/75c09b18-6090-44df-a18d-moreblahd1fe06ab1cde

(404 - 失败) http://localhost:3000/account/changeforgottenpassword/blahblah@test.com/75c09b18-6090-44df-a18d-moreblah

app.module.ts 中,我配置了以下路由(为简洁起见缩短了代码):

    import { RouterModule } from '@angular/router';

    RouterModule.forRoot([
      { path: 'login', component: LoginComponent },
      { path: 'login/forgotpassword', component: ForgotPasswordComponent },
  { path: 'account/changeforgottenpassword/:type/:id', component: ChangePasswordComponent },
      { path: 'dashboard', component: DashboardComponent },
      { path: '', redirectTo: 'login', pathMatch: 'full' },
      { path: '**', component: PageNotFoundComponent }
    ])

所有路线都有效。但是,需要配置 account/changeforgottenpassword 路径,以便相应的 ChangePasswordComponent 仅显示第二个 URL、第三个 URL 等

我尝试使用通配符路径(例如 account/changeforgottenpassword/**),但没有成功。

最后,当我使用参数中指定的电子邮件地址访问 URL 时,我得到的只是一个 404。

代码片段在这里:https://plnkr.co/edit/g2wkInKnWnbRhgqVHkRg?p=catalogue

感谢您的宝贵时间,S.O。社区!

您需要定义通配符是什么,例如:

{ path: 'account/changeforgottenpassword/:type/:id', component: AnotherComponent }

然后可以通过 ActivatedRouteSnapshotActivatedRoute.

访问这些内容
@Component()
export class AnotherComponent implements OnInit {
    private _route: ActivatedRouteSnapshot;

    constructor(route: ActivatedRouteSnapshot) {
        this._route = route;
    }

    ngOnInit() {
        // http://localhost:3000/account/changeforgottenpassword/blahblahtest/75c09b18-6090-44df-a18d-moreblah
        console.log(this._route.params['type']) // blahblahtest
        console.log(this._route.params['id']) // 75c09b18-6090-44df-a18d-moreblah
    }
}