简体   繁体   English

Angular 5 页面重新加载

[英]Angular 5 page reload

Could someone hellps me?有人可以帮帮我吗? I Use Angular 5. When I navigate to some route like this.router.navigate(['somePath']);我使用 Angular 5。当我导航到像this.router.navigate(['somePath']);这样的路线时this.router.navigate(['somePath']); my url in browser changed to basicUrl/somePath .我在浏览器中的 url 更改为basicUrl/somePath Everything is ok until page reload in browser.一切正常,直到页面在浏览器中重新加载。 After it I see my component (no navbar and other things, only my component html).之后我看到我的组件(没有导航栏和其他东西,只有我的组件 html)。 How can I improve this behaviour?我怎样才能改善这种行为? Now I have in every my component现在我的每个组件都有

ngOnInit() {
    this.location.replaceState('/');
}

to replace browser url.替换浏览器网址。 But I do not like this solution.但我不喜欢这个解决方案。

You should navigate relatively : 您应该相对导航:

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