无法接收 Angular 路由中发送的查询参数

问题描述

我有一个组件可以路由到另一个组件并传递一些条件参数

这是定义路由的代码:

redirect(topicname : string){
    alert(topicname)
    this.router.navigate(['/chapters'],{ queryParams: { topic: topicname } });
  }

在我定义的 Chapters.component.ts 文件上:

export class ChapterstemplComponent implements OnInit {
  topic : string;
  constructor( private route : ActivatedRoute) { 
    this.topic= this.route.snapshot.params.topic;
    alert( this.route.snapshot)
  }

但是 this.topic 没有收到任何值。我想在我的 Chapters.component 的 HTML 文件中使用它。 注意:警报消息确认“topicname”在第一个片段中发送良好 但是在第二个片段中,路由没有收到任何参数 这是相同的图像:

第一个/发送警报:

enter image description here

第二次/收到警报:

enter image description here

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)