消失queryParams路由器角度

问题描述 投票:0回答:1

我正在使用queryParams在我的网址中包含搜索参数。然后我有以下内容:

app.routing.module.ts

{path: 'buscar', component: BuscarComponent}

component.ts

 goSearch() {
    this.router.navigate(['/buscar'], { queryParams: { query: 'larapa' }} );
 }

component.html

<button (click)="goSearch()">myLink</button>

然后,结果我得到http://localhost:4200/buscar?query=larapa,但立即?query=larapa消失了,最终我得到了http://localhost:4200/buscar

这是正常行为吗?我设置错误吗?如何解决此问题?

angular angular2-routing
1个回答
0
投票

如果您想保留自己的参数,如何使用应用程序路由参数?

在App.routing.module.ts中

{path: 'buscar:query', component: BuscarComponent}

然后您可以像这样http://localhost:yourport/buscar/larapa来访问URL>

© www.soinside.com 2019 - 2024. All rights reserved.