如何解决重定向到儿童路线
我有两个组件:student-list 和 student-details
我希望当我启动应用程序时,我登陆 localhost:4200/students
当我点击详细信息时,我想在 localhost:4200/students/1/details
到达(1 = 学生证)
当我输入 localhost:4200/students
时,我被重定向到 localhost:4200
但是当我点击一个细节时,我没有被重定向。我的按钮是这样做的:
details(student: Student) {
console.log('details clicked!')
this.router.navigate([student.id,'details']);
}
我的路由(app-routing.module.ts)是这样的:
const routes: Routes = [
{ path: '**',redirectTo: 'students',pathMatch: 'full'},{ path: 'students',component: StudentsListComponent,children: [
{ path: '',component: StudentsListComponent },{ path: ':id/details',component: StudentDetailsComponent }
]},];
我不明白问题出在哪里。 我可能误解了儿童的工作方式。
你能帮我吗? 谢谢
解决方法
将您的路线顺序更改为 -
const routes: Routes = [
{
path: 'students',component: StudentsListComponent,children: [
{ path: '',component: StudentsListComponent },{ path: ':id/:details',component: StudentDetailsComponent }
]
},{ path: '**',redirectTo: 'students',pathMatch: 'full'},];
详细方法
details(student: Student) {
console.log('details clicked!')
this.router.navigate(['students',{id: student.id,details: 'details'}]);
}
看看它是否有效
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。