组件在列表中搜索数据取决于URL,如果找不到数据,它将用户重定向到404页面,一切正常,用户不会注意到任何差异,但是我在安慰
ngOnInit() {
this.activatedRoute.paramMap.subscribe(params => {
this.index = +params.get("index"); // Get the index of the palette from the link
this.palette = this.colorsServices.getPalette(this.index);
if (typeof this.palette == 'undefined') { // If the palette not exist
this.router.navigate(["/not-found"]);
}
});
}
const routes: Routes = [
{path: '', component: CardsComponent},
{path: 'palette/:index', component: PaletteComponent},
{path: 'not-found', component: NotFoundComponent},
{path: "**", component: NotFoundComponent}
];