Angular 6中的带有查询字符串的URL与路径不匹配。
创始人
2024-10-16 10:30:25
0

在Angular中,路径和查询字符串是分开处理的,因此在路由配置中无法直接匹配包含查询字符串的URL。如果想要匹配包含查询字符串的URL,可以使用通配符路由。

以下是一个示例解决方法:

  1. 在路由配置文件中定义通配符路由,例如:
const routes: Routes = [
  // 其他路由配置...

  // 通配符路由
  { path: '**', component: NotFoundComponent }
];
  1. 创建一个NotFoundComponent组件,用于处理所有未匹配的URL,例如:
import { Component } from '@angular/core';

@Component({
  template: `
    

404 - Not Found

The page you requested does not exist.

` }) export class NotFoundComponent { }
  1. 在项目的根模块中导入NotFoundComponent,并将其添加到declarations和exports数组中。
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';

import { AppComponent } from './app.component';
import { NotFoundComponent } from './not-found.component';

@NgModule({
  imports: [BrowserModule],
  declarations: [AppComponent, NotFoundComponent],
  exports: [NotFoundComponent],
  bootstrap: [AppComponent]
})
export class AppModule { }

通过以上步骤,当Angular应用程序收到一个未匹配的URL时,会自动导航到NotFoundComponent组件,显示404错误页面。

请注意,如果希望在应用程序中自定义处理未匹配的URL,可以根据实际需求对NotFoundComponent进行修改。

相关内容

热门资讯

玩家攻略!wepoker辅助器... 1、玩家攻略!wepoker辅助器安装包,wepoker俱乐部辅助器,细节揭秘(有挂攻略)(UU p...
一分钟揭秘!大菠萝免费辅助,w... 一分钟揭秘!大菠萝免费辅助,wepoker免费透视,新版2025教程(有挂教程);支持2-10人实时...
必备辅助推荐!hhpoker免... 《必备辅助推荐!hhpoker免费透视脚本,pokemomo辅助工具,详细教程(有挂软件)》 hhp...
查到实测!德普之星私人局透视,... 查到实测!德普之星私人局透视,xpoker辅助工具,规律教程(有挂辅助)这是由厦门游乐互动科技有限公...
总算了解!德州圈脚本,hhpo... 1、总算了解!德州圈脚本,hhpoker德州机器人,曝光教程(有挂透明)。2、hhpoker德州机器...
重大来袭!德州透视是真的假的,... 重大来袭!德州透视是真的假的,hhpoker可以开挂吗,解说技巧(有挂透视)1、玩家可以在德州透视是...
发现一款!impoker辅助,... 发现一款!impoker辅助,来玩德州破解器,微扑克教程(有挂教程)是由北京得来玩德州破解器黑科技有...
指导大家!hhpoker有没有... 指导大家!hhpoker有没有作弊挂,agpoker辅助,wpk教程(有挂教程)1、不需要AI权限,...
玩家必知教程!德普之星透视辅助... 玩家必知教程!德普之星透视辅助软件激活码,wepoker透视脚本,教你教程(有挂教程);玩家必备必赢...
每日必看!wepoker透视底... 每日必看!wepoker透视底牌脚本,hhpoker底牌透视脚本,安装教程(有挂技巧);《WPK辅助...