angular - Angular 8 - 导航到相同的路由路径时处理路由订阅
问题描述
我正在从后端应用程序接收路由通知,以加载 Angular 组件。例子:
// Current route "/example1/path1"
let route = "/example2/path1"; //route received from back-end
this.router.navigate([route]); // OK: navigates to component associated to "/example2/path1" path
此外,在每个组件中,我都在订阅中处理路由通知:
this.route.params.subscribe(params => {
...
}
});
尽管如此,我在一些接收到的路线上导航到相同的组件时遇到了一些麻烦,比如说:
// Current route "/example1/path1"
let route = "/example1/path1"; //route received from back-end (SAME ROUTE PATH)
this.router.navigate([route]); // NOK: route notification not received in subscription
我的问题是:当应用程序需要导航到同一条路线时,是否有任何方法可以接收此订阅通知?查询参数对我来说是一个有效的解决方案,例如:“/example1/path1?timestamp=1234567”,但是我不知道如何在不创建单独的解析方法的情况下分别解析“timestamp”和“path1”......
我将不胜感激有关此的任何帮助或建议。
解决方案
见https://angular.io/guide/router#getting-route-information
this.router.navigate(["/example1/path1"],{timestamp: 1234567});
import {ActivatedRoute} from "@angular/router";
constructor(private route: ActivatedRoute) {}
ngOnInit() {
// "/example1/path1?timestamp=1234567"
this.route.params.subscribe(params => {
this.timestamp = params['timestamp'];
});
}
推荐阅读
- text - 在 Weka 中将文本转换为 .arff 的问题
- java - java process finishes after some time with no particular reason
- css - How to correctly reference .css file from handlebars while making /public/css and /public/img folders static?
- excel - 工作表函数 Sum-if 导致错误类型不匹配
- docusignapi - What is the DocuSign rest api endpoint that mimics Share to Folder action for templates?
- java - How to throw Spring @Valid "exception"?
- mysql - mySQL Left outer join not selecting possible all data
- python - 当一个(或多个)值未知/通配符时计算出列表的排列数量
- r - 如何更改 MendelianRandomization 函数中的内部函数以更改输出中的小数位?
- javascript - d3.js - 使用 .selectAll() 根据属性值选择节点元素