Angular 4 抛出 Cannot match any paths 错误与 URL 中的 XSS 脚本

2024-04-22

我正在 Angular 4 中开发一个应用程序。当我尝试为功能模块编写路由时,出现错误:Error: Cannot match any routes.

这是我使用的路线代码:

const COURSE_ROUTES: Routes = [
  {path: '', redirectTo: '/', pathMatch: 'full'},
  {path: ':name', component: CourseComponent},
  {path: '**', component: ErrorComponent}
];

路由工作正常并且正在前往CourseComponent当路线类似于course/angular or course/some-course-name但是当我尝试将一些 XSS 脚本注入同一路由时,例如

course/<script>alert('0wn3d')</script>,

它抛出一个错误

ERROR Error: Uncaught (in promise): Error: Cannot match any routes. URL Segment: ''0wn3d'' Error: Cannot match any routes. URL Segment: ''0wn3d'

尽管我已经为错误路线编写了通配符条目。我已经测试过

{path: '**', component: ErrorComponent}

显示 404 错误页面,通过删除

{path: ':name', component: CourseComponent}

并使用一些随机 url 运行应用程序,例如course/some-course

请帮我解决这个问题。提前致谢。


不可能有/作为根 URL。

  {path: 'some-name:name',pathMatch: 'full',component:CourseComponent}

记录在这里 https://angular.io/guide/router

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Angular 4 抛出 Cannot match any paths 错误与 URL 中的 XSS 脚本 的相关文章

随机推荐