【问题标题】:How pass parameters from two url without show them in the url [duplicate]如何从两个 url 传递参数而不在 url 中显示它们 [重复]
【发布时间】:2020-05-27 09:16:26
【问题描述】:

我需要从 URLA 或 urlB 传递参数,但必须显示 urlB(所以我不能使用 skiplocation=true)。

在我的 ts 中(在 URLA 中):

this.router.navigate([URLB], {
                queryParams:
                {
                    name: "erika"

                }
            });

当我接受参数时:

 this.activatedRoute.queryParams.subscribe(params => {
      this.name = params['name'];

    });

问题是它以这种方式向我显示 url URLB?name=erika 而我不想这样做,但我希望它向我显示 URLB 并向我传递隐藏参数。谁能帮帮我?

【问题讨论】:

  • 你能再解释一下吗。目前还不清楚你想要什么。我建议您不要使用查询字符串或路径变量,因为查询字符串和路径变量参数是可见的。我知道拥有不可见参数的唯一方法是使用 HTTP POST 动词中的有效负载。
  • 不可能。你能做的就是保持 url 到 URL A 并仍然导航

标签: angular angular-routing angular-router angular-activatedroute


【解决方案1】:

您可以在 NavigationExtras 中使用状态:

设置数据:

this.router.navigate(['yoururl'], { state: yourObject });

获取数据:

this.router.getCurrentNavigation().extras.state

https://angular.io/api/router/Router#navigate

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

如果您想使用服务,请阅读:Sharing Data between Components

【讨论】:

    猜你喜欢
    • 2020-08-13
    • 1970-01-01
    • 1970-01-01
    • 2023-04-07
    • 1970-01-01
    • 2020-12-09
    • 2018-07-05
    • 2019-02-05
    • 2022-01-25
    相关资源
    最近更新 更多