角路由错误:“ ViewDestroyedError:尝试使用被破坏的视图:detectChanges”

时间:2019-07-17 00:41:20

标签: angular routing

组件在列表中搜索数据取决于URL,如果找不到数据,它将用户重定向到404页面,一切正常,用户不会注意到任何差异,但是我在安慰 enter image description here

重定向代码

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}
];

0 个答案:

没有答案