可以使用 router.events
流检测路由更改。 (How to detect a route change in Angular 2?)。
但我不确定如何检测浏览器 URL 更改。
最佳答案
你可以注入(inject)Location
并订阅它
import { Location } from '@angular/common';
...
constructor(location:Location) {
location.subscribe(val => console.log(val));
}
正如哈利所说。这仅通知有关 popState 事件(路由器或类似代码更改 URL)
关于javascript - 如何检测 Angular 2 中的 URL 变化?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39907974/