我正在 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
请帮我解决这个问题。提前致谢。