【问题标题】:disappears queryParams router Angular消失 queryParams 路由器 Angular
【发布时间】:2019-10-23 23:39:56
【问题描述】:

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

app.routing.module.ts

{path: 'buscar', component: BuscarComponent}

组件.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】:

如果你想保留你的参数,使用 app-routing 参数怎么样?

在 App.routing.module.ts 中

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

那么你就可以像http://localhost:yourport/buscar/larapa这样访问url了

【讨论】:

  • 我的最终路径需要采用这种格式 http://localhost:4200/search? query=larapa 因为我使用 algolia 作为搜索提供程序
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2019-08-15
  • 2018-12-04
  • 1970-01-01
  • 2023-02-18
  • 2018-05-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多