![](/img/trans.png)
[英]Angular 2 How to detect back button press using router and location.go()?
[英]Angular 6 route params reload after Location.go
為了避免任何組件重新加載,我使用Location.go
來更改我的第一個組件 ( SearchboxComponent ) 的 URL。
問題是我在第二個組件 ( ListingComponent ) 中使用路由參數來反映某些鏈接、分頁等中的 URL 更改。但我的訂閱未檢測到新 URL,並且參數不會更改。 我可以讓路由器模塊重新解析 URL 以填充新參數嗎?
列表組件
this.route.params.subscribe( async (params: IListingUrlParams) => {
console.log('params', params);
});
搜索框組件
const url = this.parametersService.searchParamsToUrl(params);
// this.router.navigate([url]); This works but reloads my main component
this.listingsService.getList(params); // Fetch the new data before navigation
Location.go(url); // This works but params are not reloaded
如果你想更新你當前的路由參數。
讓我們說你的路線:
路徑/:id
當前路徑:路徑/123
在組件中:
import { Location } from '@angular/common';
constructor(private location: Location) { }
updateRoute(){
let url = this.location.path().replace('123', '456');
this.location.go(url);
}
更新路徑:路徑/456
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.