Angular路由只将某些路由路由到404页面,不会将子路由错误路由到404页面。
创始人
2024-10-28 05:31:09
0

可以使用控制台打印来检查错误信息,然后将所有错误路由到404页面,包括子路由的错误。以下是一个示例代码:

import { NgModule } from '@angular/core';
import { Routes, RouterModule } from '@angular/router';
import { NotFoundComponent } from './not-found/not-found.component';

const routes: Routes = [
  {
    path: '',
    loadChildren: () => import('./home/home.module').then(m => m.HomeModule)
  },
  {
    path: '**',
    component: NotFoundComponent
  }
];

@NgModule({
  imports: [RouterModule.forRoot(routes)],
  exports: [RouterModule]
})
export class AppRoutingModule { }

在上面的代码中,NotFoundComponent是你的404组件,如果路由无法匹配任何其他路由,则会自动路由到该组件。

然后可以在子路由中添加一个通配符路由来使普通路由错误也能被捕获并路由到404页面:

import { NgModule } from '@angular/core';
import { Routes, RouterModule } from '@angular/router';
import { NotFoundComponent } from '../not-found/not-found.component';
import { ChildComponent } from './child.component';

const routes: Routes = [
  {
    path: '',
    component: ChildComponent
  },
  {
    path: '**',
    component: NotFoundComponent
  }
];

@NgModule({
  imports: [RouterModule.forChild(routes)],
  exports: [RouterModule]
})
export class ChildRoutingModule { }

这样,当访问不存在的子路由时,它将路由到404页面。

相关内容

热门资讯

不少玩家反映!wepoker私... 不少玩家反映!wepoker私人局透视方法,德普之星透视,本来是有挂(有挂透明挂)1、上手简单,内置...
有了最新消息!wepoker有... 有了最新消息!wepoker有辅助功能吗,智星菠萝有挂吗,本来真的是有挂(有挂助手)1、智星菠萝有挂...
受玩家影响!wepoker辅助... 受玩家影响!wepoker辅助分析器,德普之星透视辅助软件是真的吗,其实确实有挂(了解有挂)1、每一...
有了最新消息!wepokerp... 有了最新消息!wepokerplus透视脚本免费,德普之星透视软件免费入口官网,确实确实有挂(证实有...
黑科技技巧!wepoker脚本... 黑科技技巧!wepoker脚本下载,德扑之星透视辅助插件,果然真的是有挂(有挂详细)1、完成德扑之星...
总结辅助挂!wepoker透视... 总结辅助挂!wepoker透视苹果系统,红龙poker辅助,一贯存在有挂(有挂教程)1.红龙poke...
近年来!智星菠萝有挂吗,如何下... 近年来!智星菠萝有挂吗,如何下载德普之星辅助软件,本来存在有挂(有挂助手)1、如何下载德普之星辅助软...
今日!wepoker透视版下载... 今日!wepoker透视版下载,德扑之星怎么开辅助,切实真的是有挂(有挂存在)1、进入到德扑之星怎么...
据统计!wepoker透视最简... 据统计!wepoker透视最简单三个步骤,德普之星透视,真是真的有挂(有挂教学)1、金币登录送、破产...
近年来!hhpoker破解工具... 近年来!hhpoker破解工具,德扑之星透视免费,切实是真的有挂(有挂分享)1、完成德扑之星透视免费...