[英]Angular 5 page reload
有人可以幫幫我嗎? 我使用 Angular 5。當我導航到像this.router.navigate(['somePath']);
這樣的路線時this.router.navigate(['somePath']);
我在瀏覽器中的 url 更改為basicUrl/somePath
。 一切正常,直到頁面在瀏覽器中重新加載。 之后我看到我的組件(沒有導航欄和其他東西,只有我的組件 html)。 我怎樣才能改善這種行為? 現在我的每個組件都有
ngOnInit() {
this.location.replaceState('/');
}
替換瀏覽器網址。 但我不喜歡這個解決方案。
您應該相對導航:
import { Router, ActivatedRoute } from '@angular/router';
this.router.navigate(['somePath', ], {relativeTo: this.activatedRoute});
window.location.reload 在按鈕點擊事件中
<button type="button" mat-raised-button color="warn" onclick="window.location.reload();">
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.