在Location.go()之后,History.back()不会触发ActivatedRoute.paramMap

问题描述 投票:0回答:1

考虑此URL:

http://localhost:4200/items

当我在GUI中打开(扩展)元素时,我使用Location.go()更新URL]

http://localhost:4200/items;openedId=123

[当我按下后退按钮时,URL更改回http://localhost:4200/items,但是我对ActivatedRoute.paramMap的订阅未触发

。 (因此我的项目保持打开状态)

奇怪的是,当我连续打开两个元素,然后回击两次时会触发它:

Open main page -> http://localhost:4200/items
Open item 123  -> http://localhost:4200/items;openedId=123
Open item 456  -> http://localhost:4200/items;openedId=456

Back to http://localhost:4200/items;openedId=123 -> ActivatedRoute.paramMap triggered
Back to http://localhost:4200/items -> ActivatedRoute.paramMap triggered (!)

为什么它不是第一次触发?为什么需要两个历史记录条目才能起作用?我很困惑。

更新:这是我在paramMap中侦听更改的方式:

  public ngOnInit() {

    this.subscriptions.add(this.activatedRoute.paramMap.subscribe(paramMap => {
      this.handleNavigation(paramMap);
    }));
}

考虑此URL:http:// localhost:4200 / items当在GUI中打开(扩展)元素时,我使用Location.go()更新URL:http:// localhost:4200 / items; openedId = 123当我打后背时...

angular angular-routing browser-history
1个回答
0
投票

我不建议使用Location.go()函数。

© www.soinside.com 2019 - 2024. All rights reserved.