如何使用 Angular 2 在 URl 中使用问号

Rav*_*avi 5 javascript angular2-forms angular2-routing angular

我是 Angular 2 的新手,这里显示了将显示我的 url 的路由器代码。 现在路由器代码 ,当我运行该代码时,网址看起来像这样..

本地主机:50465/促销%3Fid%3D/51059

在该网址中显示%3F而不是问号(?)和%3D而不是等于(=)。展示如何显示我的原始网址。我的代码看起来像那样。

我想这样输出: http://localhost:50465/promotion?id=132

如何才能实现这一点,请帮助我。

请帮我..!!

Rav*_*hah 4

在您的场景中,您可以使用如下所示的路由器代码:

{       
    path: 'home/promotiondetail',        
    component: component name
}
Run Code Online (Sandbox Code Playgroud)

在你的 html 端,你可以声明你的路由器代码如下所示:

[routerLink]="['promotiondetail']" [queryParams]="{ id: {{id}} }"
Run Code Online (Sandbox Code Playgroud)

显示当您运行此代码时,您可以获得如下所示的网址:

http://localhost:50465/promotion?id=132

希望,这很有用。欲了解更多信息,请使用此链接:https://angular-2-training-book.rangle.io/handout/routing/routeparams.html