我正在使用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
这是正常行为吗?我设置错误吗?如何解决此问题?
如果您想保留自己的参数,如何使用应用程序路由参数?
在App.routing.module.ts中
{path: 'buscar:query', component: BuscarComponent}
然后您可以像这样http://localhost:yourport/buscar/larapa来访问URL>