angular - 角度刷新组件
问题描述
我在顶部导航栏中有位置下拉菜单。在更改位置时,我必须根据该位置数据加载整个应用程序,因此我需要刷新所有组件数据,这就是我接近这一步的原因。
core.js:5847 错误错误:未捕获(承诺):错误:无法匹配任何路由。URL 段:“RefreshComponent”错误:无法匹配任何路由。URL 段:“刷新组件”
constructor(
private router: Router,
) { }
我使用了 javascript setTimeout(() => { location.reload(); });
,它运行良好,我不想重新加载页面,只想刷新我在代码下面尝试过的组件。但是当我使用控制台错误来了。
changeLocation(locationData) {
this.router.navigateByUrl('/RefreshComponent', { skipLocationChange: true }).then(() => {
this.router.navigate([this.router.url]);
});
}
我缺少任何配置吗?
解决方案
您的路线配置中可能没有RefreshComponent
路线。
至于 refresing 你的组件,只需如下修改你的函数,你不需要RefreshComponent
路由。
替换navigateByUrl('/RefreshComponent',...
为navigateByUrl('/',...
changeLocation(locationData) {
// save current route first
const currentRoute = this.router.url;
this.router.navigateByUrl('/', { skipLocationChange: true }).then(() => {
this.router.navigate([currentRoute]); // navigate to same route
});
}
推荐阅读
- java - MediaRecorder 崩溃
- javascript - 试图优化早期的“Konami代码”功能
- android - 如何从java中的房间数据库中获取自动生成的ID?
- c# - 当 .NET 核心 API 返回带有 XSRF-TOKEN 的响应时,Angular(客户端)未将 XSRF-TOKEN 添加到 cookie
- python - 关于 X 轴时间序列的重叠
- reactjs - 如何将组件添加到 window.location.href?
- docker - Findenode 在本地 geth 网络中使用 bootnode 失败:响应记录中的 IP 无效:来自非环回主机的环回地址
- mongodb - MongoDB:使用相同的公共值对不同的字段进行分组
- pytorch - 为什么使用 torch.cuda.amp.GradScaler 时比例变为零?
- javascript - k6 负载测试 - 如何从 HTML 响应中提取值