Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/29.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/19.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angular 需要将参数作为查询/路径传递,但不应在URL上可见_Angular_Typescript_Angular6 - Fatal编程技术网

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

Angular 需要将参数作为查询/路径传递,但不应在URL上可见,angular,typescript,angular6,Angular,Typescript,Angular6,我需要将一个参数从一个路由传递到另一个路由,但它不应该对用户可见。我需要Angular 6。如果您不想更改URL,可以使用skipLocationChange策略 您可以使用 然后使用Angular和服务读取并覆盖URL历史记录 它并不优雅,但很有效,并且达到了你的要求 位置历史记录的检查和重写示例: this.router.events.pipe(filter(event => event instanceof NavigationEnd)) .subscribe((event: Nav

我需要将一个参数从一个路由传递到另一个路由,但它不应该对用户可见。我需要Angular 6。如果您不想更改URL,可以使用
skipLocationChange
策略

您可以使用

然后使用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中,您不能将其作为查询或路径参数传递。您可以使用@Input Decorator并通过该变量传递值。您可以在服务中保留该值。我有来自response的变量,需要将其传递到另一个ts组件,它将路由到下一步,同时我不想在url上查看该变量。