同一路线的角力载荷 [英] Angular Force load of same route

查看:27
本文介绍了同一路线的角力载荷的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一条通往计算器的路线.该人可能会点击计算,屏幕会显示结果.这很好.然后他们可能会转到导航栏并再次单击相同的计算器,我的意思是他们正在单击相同的路线.我想屏幕重新路由,所以他们本质上是重新开始,刷新屏幕.当然路线不会改变,屏幕也不会改变,因为它们在同一条路线上.有没有办法强制路由重新加载或刷新.我有几个不同的路线,不同的组件需要这个.因此,如果我需要编写代码来处理它们,我希望它在服务中而不是在组件中.我最好在设置路线时喜欢它.

I have a route that goes to a calculator. The person might hit calculate and the screen shows the result. Which is fine. They then may go up to the navbar and click the same calculator again, by that I mean they are clicking the same route. I would like to screen to re-route so they are in essence starting over, refreshing the screen. Of course the route does not change nor does the screen change because they are on the same route. Is there some way to force the route to re-load or refresh. I have several different routes with different components that need this. So if I need to write code to handle them all I would like it to be in a service and not in the component. Preferably I would like it when I am setting up the routes.

推荐答案

Angular 5 的一个很酷的特性就是能够在需要时重新加载/刷新同一页面.你只需要在你的配置中设置它

One of the cool features of Angular 5 is precisely the ability to reload/refresh the same page in case you want it. You just need to set it on your configuration

providers: [
  // ...
  RouterModule.forRoot(routes, {
onSameUrlNavigation: 'reload'
  })
]

它是所谓的路由器 ExtraOptions 的一部分.如果您需要更多详细信息,可以在此处查看文档

It’s part of what’s called ExtraOptions for router. You can check the documentation here if you need more details

这篇关于同一路线的角力载荷的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆