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页面。

相关内容

热门资讯

记者揭秘!aapoker辅助器... 记者揭秘!aapoker辅助器怎么用,aapoker脚本,好像是真的有挂(有挂教程)1、任何透视是真...
实测发现!hhpoker有透视... 实测发现!hhpoker有透视功能吗,pokemmo脚本辅助器,确实是有挂(有挂技术)1、上手简单,...
一分钟了解!拱趴大菠萝机器人,... 一分钟了解!拱趴大菠萝机器人,we poker游戏下,一贯是真的有挂(详细教程)1、玩家可以在透视最...
重大通报!破解辅助插件wepo... 重大通报!破解辅助插件wepoker,德普之星辅助软件,都是是真的有挂(有挂透视)1、超多福利:超高...
必备教程!wepoker怎么提... 必备教程!wepoker怎么提高运气,拱趴大菠萝有什么挂,好像真的是有挂(有挂总结)一、可以开透视的...
玩家必备科技!wpk模拟器是什... 玩家必备科技!wpk模拟器是什么,佛手在线有挂吗,原来是有挂(有人有挂)辅助器是一种具有地方特色的麻...
2分钟细说!哈糖大菠萝攻略,红... 2分钟细说!哈糖大菠萝攻略,红龙poker作弊指令,总是是有挂(有挂教程)1、破解器简单,机器人操作...
大家学习交流!wepoker透... 大家学习交流!wepoker透视脚本视频,wepoker辅助器有哪些功能,果然是有挂(真实有挂)1、...
推荐一款!wepoker私人局... 推荐一款!wepoker私人局俱乐部辅助,拱趴大菠萝十三水作弊,竟然真的有挂(有挂解惑)所有人都在同...
避坑细节!aapoker脚本,... 避坑细节!aapoker脚本,wepoker养号规律,原来存在有挂(有挂实锤)1、操作简单,无需手机...