如何使用 angular 2 路由器重新加载当前路由

编程入门 行业动态 更新时间:2024-10-26 23:26:54
本文介绍了如何使用 angular 2 路由器重新加载当前路由的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在使用带有 hashlocation 策略的 angular 2.

I am using angular 2 with hashlocation strategy.

该组件加载了该路由:

"departments/:id/employees"

到目前为止还好.

在我成功批量保存多个编辑过的表行后,我想通过以下方式重新加载当前路由 URL:

After I do a successful batch save of multiple edited table rows I want to reload the current route URL via:

this.router.navigate([`departments/${this.id}/employees`]);

但是什么都没发生,为什么?

But nothing happens, why?

推荐答案

在控制器中创建一个函数,像这样重定向到预期的路由

Create a function in the controller that redirects to the expected route like so

redirectTo(uri:string){ this.router.navigateByUrl('/', {skipLocationChange: true}).then(()=> this.router.navigate([uri])); }

然后像这样使用它

this.redirectTo('//place your uri here');

此功能将重定向到一条虚拟路由,并在用户没有意识到的情况下快速返回到目标路由.

this function will redirect to a dummy route and quickly return to the destination route without the user realizing it.

更多推荐

如何使用 angular 2 路由器重新加载当前路由

本文发布于:2023-10-31 17:23:44,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1546766.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:路由   如何使用   路由器   加载   angular

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!