嗨,我有只有静态方法(助手)的“静态类”实用程序:
export class Utils {
static doSomethingAndRedirect() {
...doo something...
redirectTo->'/home'
}
}
那么redirectTo
代码应该是什么样子的呢?
嗨,我有只有静态方法(助手)的“静态类”实用程序:
export class Utils {
static doSomethingAndRedirect() {
...doo something...
redirectTo->'/home'
}
}
那么redirectTo
代码应该是什么样子的呢?
您对尝试解决的用例采取了错误的方法。看看ngrx/store
和ngrx/effects
。
简而言之,您定义了修改应用程序状态的操作和减速器。接下来,您可以对具有不同副作用 ( ngrx/effects
) 的不同操作做出反应,例如在我的应用程序中:
/dashboard
组件这可以很好地分离关注点:
我在我的案例中找到的最佳解决方案只是......将参数“路由器”添加到静态函数参数列表中:
static doSomethingAndRedirect(router) {
...doo something...
router.navigateByUrl('home'); // redirect
}
这是静态助手便利性和非静态“角度方式”之间的一种折衷。