如何使用 angular 片段将数据从一个页面传递到另一个页面?

How to pass data from one page to another page using angular fragments?

我试图在导航到另一个页面时向另一个页面发送数据。

this.router.navigateByUrl('/homePage', { fragment:"hello world"});

我不确定如何在我的主页中接收我的片段。 我在我的主页下面尝试了他的内容。

ngOnInit() {
    this.router.fragment.subscribe((fragment: any) => {
      console.log("My hash fragment is here => ", fragment)
    })
}

I'm getting undefined i'm not sure how to receive the fragment any help...

我可以通过更改以下

在我的主页上打印 console.log
this.router.navigateByUrl('/homePage', { fragment:"hello world"});

至此

this.router.navigate(['parameter-to-device'], { fragment:"hello world"});