繁体   English   中英

Angular 5 页面重新加载

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM