JSO*_*SON 0 angular-routing ngrx ngrx-router-store
我正在尝试调度相对于组件路线的路由器商店导航操作。路由跟踪日志显示,用于导航的相对路径是应用程序路径而不是组件路径。
return of(
new routerActions.Go({
path: ['./', payload.rootPath],
extras: { relativeTo: this.route },
}),
);
constructor(
private actions$: Actions,
private route: ActivatedRoute,
) {}
Run Code Online (Sandbox Code Playgroud)
我正在ActivatedRoute效果模块构造函数中注入,这似乎是这里的问题。我如何才能在组件之外获取激活的路线并将其传递给导航动作?
ActivatedRoute特定于每个路由组件。
这给您几个选择。
let route = this.router.routerState.root;
while (route.firstChild) {
route = route.firstChild;
}
return route.snapshot;Run Code Online (Sandbox Code Playgroud)
constructor(private store: Store<AppState>, private activatedRoute:ActivatedRoute) {}
doSomething() {
this.store.dispatch(new Action.YourAction({ id: actionId, route: activatedRoute });
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
614 次 |
| 最近记录: |