当我在angular 7中直接从另一个网页打开应用程序时,无法初始化路由参数

当我在angular 7中直接从另一个网页打开应用程序时,无法初始化路由参数,angular,angular-router,Angular,Angular Router,我是angualr 7的新手,我正在尝试为用户构建仪表板,用户将从电子邮件中获取仪表板的url 例如: 尊敬的用户: 请使用此链接打开门户(指向localhost:4200/dashboard/myuserid的超链接) 我试图通过使用角度路由器和路径参数来实现这一点 批准模块ts 我可以像这样在ngOnInit中使用ActivatedRoute读取path变量 ngOnInit() { let id = this.route.snapshot.paramMap.get('id');

我是angualr 7的新手,我正在尝试为用户构建仪表板,用户将从电子邮件中获取仪表板的url

例如:

尊敬的用户:

请使用此链接打开门户(指向localhost:4200/dashboard/myuserid的超链接)

我试图通过使用角度路由器和路径参数来实现这一点

批准模块ts

我可以像这样在ngOnInit中使用ActivatedRoute读取path变量

ngOnInit() {
      let id = this.route.snapshot.paramMap.get('id');

  }
当我尝试使用邮件中的超链接访问页面时,我遇到以下错误

Error: Cannot match any routes. URL Segment: 'dahboard/B50A43A6EE303E9D239A1F62956B8F2D'
    at ApplyRedirects.push../node_modules/@angular/router/fesm5/router.js.ApplyRedirects.noMatchError (router.js:1384)
    at CatchSubscriber.selector (router.js:1365)
    at CatchSubscriber.push../node_modules/rxjs/_esm5/internal/operators/catchError.js.CatchSubscriber.error (catchError.js:33)
    at MapSubscriber.push../node_modules/rxjs/_esm5/internal/Subscriber.js.Subscriber._error (Subscriber.js:80)
    at MapSubscriber.push../node_modules/rxjs/_esm5/internal/Subscriber.js.Subscriber.error (Subscriber.js:60)
    at MapSubscriber.push../node_modules/rxjs/_esm5/internal/Subscriber.js.Subscriber._error (Subscriber.js:80)
    at MapSubscriber.push../node_modules/rxjs/_esm5/internal/Subscriber.js.Subscriber.error (Subscriber.js:60)
    at MapSubscriber.push../node_modules/rxjs/_esm5/internal/Subscriber.js.Subscriber._error (Subscriber.js:80)
    at MapSubscriber.push../node_modules/rxjs/_esm5/internal/Subscriber.js.Subscriber.error (Subscriber.js:60)
    at TapSubscriber.push../node_modules/rxjs/_esm5/internal/operators/tap.js.TapSubscriber._error (tap.js:61)
但是,当我在其中一个组件中硬编码参数时,我能够打开仪表板而不会出现任何问题

<a [routerLink]="['/dashboard', 'B50A43A6EE303E9D239A1F62956B8F2D']"  
        >Dashboard</a
      >
仪表板
你知道是什么导致了这个问题吗?

dahboard和dashboard:)不一样,所以我想你应该修复你电子邮件中的链接,在其中添加“dashboard”

如果您希望404页面位于未知路径上,则应添加以下内容作为应用程序路由的最后一项:

{
  path: '**',
  component: Error404Component
}

确实是的,邮件中的链接是错误的。当路径不匹配时,有没有办法显示错误页面/组件,而不是显示空白组件?@nsivaram90我已经更新了我的答案来回答你的问题
{
  path: '**',
  component: Error404Component
}