【发布时间】:2018-09-10 12:52:09
【问题描述】:
我正在借助路由开发一个单页应用程序:
this.router.navigate(['/customer-home'], { skipLocationChange: true });
当我在上述页面时,我正在使用 REST 调用添加客户。客户更新后,我希望我的页面刷新并重新加载 /customer-home 页面视图。
我的方法如下所示:
addNewCustomer(customer) {
this.dataService.postEntity('customers', customer);
location.reload();
}
问题是location.reload刷新页面并重定向到首页。
我已经为这个位置做了一个控制台日志:
Location {replace: ƒ, assign: ƒ, href: "http://localhost:4200/", ancestorOrigins: DOMStringList, origin: "http://localhost:4200", …}
有什么办法,我可以使用路由重新加载我的页面和数据,我不想在地址栏中显示 URL。
PS 我已经尝试重定向到其他组件,然后返回到当前组件,但它不会重新加载数据,也不会显示最新添加的客户。
【问题讨论】:
-
可能是因为
skipLocationChange: true导航历史没有看到路线变化。你为什么这样做?你为什么要重新加载页面? -
确实如此。为了获得最新的更改,我正在这样做。我现在在 cmets 中得到了一个解决方案,可以在 post 上得到一个 promise 并在当前数组中添加实体。
标签: angular typescript routing routes angular4-router