需要将param作为查询/路径传递,但在URL上不应可见



我需要将一个参数从一个路由传递到另一个路由,但它不应该对用户可见。我需要它在角6。

您可以使用矩阵参数。

然后使用Angular位置和路由器服务读取并覆盖URL历史记录。

它不优雅,但很管用。。并实现您的要求。

位置历史记录的检查和重写示例:

this.router.events.pipe(filter(event => event instanceof NavigationEnd))
.subscribe((event: NavigationEnd) => {
const matrixParams = this.location.path().split(';');
... do something with the matrixParam
if(matrixParams.length > 1) {
this.location.replaceState(matrixParams[0])
}
}));

其他想法(如前所述(

  • 使用服务传递数据,在OnInit中检查
  • 如前所述,使用@Input((在组件之间传递

如果您不想更改URL,可以使用skipLocationChange策略。

https://angular.io/api/router/NavigationExtras

相关内容

最新更新