相同路径的角向力负载 [英] Angular Force load of same route

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

问题描述

我有一条去计算器的路线.该人可能会点击计算,屏幕会显示结果.没关系然后,他们可能会转到导航栏并再次单击相同的计算器,这意味着他们正在单击相同的路线.我想对屏幕进行重新布线,以便从本质上说它们是从头开始,刷新屏幕.当然,路线不会改变,屏幕也不会改变,因为它们在同一条路线上.是否有某种方法可以强制路由重新加载或刷新.我有一些具有不同组件的不同路线,需要此路线.因此,如果我需要编写代码来处理它们,那么我希望它在服务中而不在组件中.设置路线时,最好选择它.

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天全站免登陆