如何使用 angular 2 路由器重新加载当前路由 [英] How to reload the current route with the angular 2 router

查看:53
本文介绍了如何使用 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 路由器重新加载当前路由的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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