代码之家  ›  专栏  ›  技术社区  ›  JSON

使用路由器商店导航有效模块时,如何激活路线?

  •  0
  • JSON  · 技术社区  · 6 年前

     return of(
            new routerActions.Go({
              path: ['./', payload.rootPath],
              extras: { relativeTo: this.route },
            }),
          );
    
     constructor(
        private actions$: Actions,
        private route: ActivatedRoute,
      ) {}
    

    ActivatedRoute 在我的效果模块构造函数,这似乎是这里的问题。如何在组件外部获取激活的路由并将其传递给导航操作?

    1 回复  |  直到 6 年前
        1
  •  6
  •   Eric S    6 年前

    ActivatedRoute特定于每个路由组件。

    这给了你几个选择。

    1. 导航根路由以返回所需的数据。

    let route = this.router.routerState.root;
    while (route.firstChild) {
    route = route.firstChild;
    }
    
    return route.snapshot;
    1. 从包中的路由组件传递ActivatedRoute。

      constructor(private store: Store<AppState>, private activatedRoute:ActivatedRoute) {}
    
      doSomething() {
        this.store.dispatch(new Action.YourAction({ id: actionId, route: activatedRoute });
      }
      
     
        2
  •  0
  •   Анастасия Куприянова    4 年前

    经过 激活路线 选择路由URL 从状态选择当前URL。

      navigateRelative$ = createEffect(() => this.actions$.pipe(
        ofType(navigateRelativeTo),
        withLatestFrom(this.store.select(selectRouterUrl)),
        tap(([{ commands }, url]) => this.router.navigate([url, ...commands])),
      ), { dispatch: false });