router.renavigate() 应该如何使用?

How should router.renavigate() be used?

在一个三层深的组件中,我有一个 ajax 调用来更新服务器上的数据,该数据显示在父控件和祖父控件中。

我希望导航到浏览器中显示的当前 url,它应该重新初始化祖父控件并从服务器获取新数据。

如果我使用相同的 url 详细信息调用 router.navigate(...) 或 router.navigateByUrl(...),则不会发生任何事情。

如果我添加一个时间戳作为参数,以便 url 发生变化,那么一切都会按我预期的方式运行。

我在另一个 post 中看到,一位用户提到使用 router.renavigate(),这听起来很完美,但显然它也不起作用(至少对于上述情况。)

这是一个错误还是按照设计?

来自这条评论https://github.com/angular/angular/issues/5916#issuecomment-214303206

ts not a bug per say. router.renavigate isn't meant for navigating again in the case that you configure your routes dynamically at runtime. router.lastNavigationAttempt is only updated when router.navigateByUrl is called. The navigateByUrl is called on initial load and unless you use it manually it won't get called again because the other navigation functions such as router.navigate and router.navigateByInstruction don't update the lastNavigationAttempt either.

我宁愿将数据绑定到服务并更新服务中的数据,并以在共享数据更改时自动更新自身的方式设计组件。