ลำดับของเส้นทางใน Angular
Angular ประมวลผลเส้นทางจากบนลงล่าง นั่นหมายความว่าควรวาง กรณีพิเศษของเส้นทางก่อน แล้วจึงตามด้วย กรณีทั่วไปมากขึ้น
ในตัวอย่างต่อไปนี้ เส้นทางแรกจะทำงานเสมอ:
const appRoutes: Routes =[
{ path: '**', component: NotFoundComponent },
{ path: 'aaaa', component: AaaaComponent},
{ path: 'bbbb', component: BbbbComponent},
];
เปลี่ยนลำดับของเส้นทางในตัวอย่างให้เป็น ลำดับที่ถูกต้อง:
const appRoutes: Routes =[
{ path: 'blog/:id', component: AaaaComponent},
{ path: 'blog/new', component: BbbbComponent},
];