如何在Angular 2中重新加载页面整个页面?

FAB*_*987 51 reload typescript angular2-routing angular

如何通过TypeScript在Angular上重新加载当前页面?

我不想更改URL参数,只是为了重新加载.

Ale*_*sky 123

从技术上讲,这可以通过window.location.reload()以下方式实现:

HTML:

<button (click)="refresh()">Refresh</button>
Run Code Online (Sandbox Code Playgroud)

TS:

refresh(): void {
    window.location.reload();
}
Run Code Online (Sandbox Code Playgroud)

更新:

这是一个基本的StackBlitz示例,显示了正在执行的刷新.请注意,window.location.reload()执行时会保留"/ hello"路径上的URL .

希望这有帮助!

  • 我想要更好的方式windows.location不跨平台... (3认同)