私は主なアプリケーションルータと複数の子ルータを持っています。親ルートからナビゲートするときに開く子ルートを指定するオプションがあります。Aurelia Child Routerは特定のルートにリダイレクトします
親ルータ:学生のための
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' }
]);
}
子供ルーター:
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});
}
}
}
(アクティベート内navigateToRoute()
を使用して)上記のシナリオが動作しない、また私はそれがだと確信しています最良の方法。 IDパラメータを含めると、アプリのメイン画面から学生プロフィール画面に直接移動するオプションはありますか?
これはバグかどうか疑問に思っています。 –
https://github.com/aurelia/router/issues/89とhttps://github.com/aurelia/router/issues/90を参照してください。後者は、パッケージに関連する可能性のある回避策があるようですが、あまりにも掘り下げてはいけません。私は子供のルートがまだロードされていないと思うので、名前を使用して動作しません。 – mgiesa
実際に私は問題を誤解している可能性があります。 Studentsページからリダイレクトするのではなく、ホームページ(デフォルトのランディングページ、student-home)に移動すると機能しますか?また、CanActivateに移動して、ルータ経由でナビゲートする代わりにRedirectToRouteを返すことができます – mgiesa