Aurelia 子路由器重定向到特定路由

LSt*_*rky 0 aurelia

我有一个主应用程序路由器和多个子路由器。我希望可以选择在从父路线导航时指定要打开的子路线。

父路由器:

configureRouter(config, router) {
  this.router = router;
  config.map([
    { route: ['','home'],      name: 'home',         moduleId: 'home/home' },
    { route: 'students/:id?',  name: 'students',     moduleId: 'students/students' },
    { route: 'staff',          name: 'staff',        moduleId: 'staff/staff' }
  ]);
}
Run Code Online (Sandbox Code Playgroud)

学生子路由器:

export class Students {

  configureRouter(config, router) {
    config.map([
      { route: ['', 'home'],    name: 'student-home',           moduleId: 'students/students-home' },
      { route: 'list',          name: 'student-list',           moduleId: 'students/student-list' },
      { route: 'profile/:id',   name: 'student-profile',        moduleId: 'students/profile/overview' },
      { route: 'lockers',       name: 'student-lockers',        moduleId: 'students/lockers/home' }
    ]);
    this.router = router;
  }

  activate(params) {
    if (params.id) {
      console.log("Going straight to a student record for: ", params);
      this.router.navigateToRoute('student-profile', {id: params.id});
    }
  }
}
Run Code Online (Sandbox Code Playgroud)

上面的场景(navigateToRoute()在 activate 中使用)不起作用,我也不确定这是最好的方法。如果我包含 id 参数,如何才能选择直接从主应用程序路由器导航到学生个人资料屏幕?

LSt*_*rky 5

我放弃了对子路由器使用命名路由。如果其他人比我更了解它们,我会很好奇。然而,我发现仅使用应用程序任何部分的 URL 路由就可以完美地工作。

this.router.navigate('#/students/profile/' + record.id);
Run Code Online (Sandbox Code Playgroud)