I've been working on a project in Angular 4 and encountered an issue while setting up routes for a feature module. The error message I'm receiving is Error: Cannot match any routes.
Below is the code snippet of the routes I've defined:
const COURSE_ROUTES: Routes = [
{path: '', redirectTo: '/', pathMatch: 'full'},
{path: ':name', component: CourseComponent},
{path: '**', component: ErrorComponent}
];
The routing works perfectly when accessing valid routes like course/angular
or course/some-course-name
. However, if I attempt to inject a malicious XSS script into the route, such as
course/<script>alert('0wn3d')</script>
,
an error is thrown stating:
ERROR Error: Uncaught (in promise): Error: Cannot match any routes. URL Segment: ''0wn3d'' Error: Cannot match any routes. URL Segment: ''0wn3d'
Despite having a wildcard entry for error routes defined as
{path: '**', component: ErrorComponent}
I have confirmed that it displays the 404 error page by temporarily removing the
{path: ':name', component: CourseComponent}
and navigating to a random URL like course/some-course
.
If anyone could assist me in resolving this issue, I would greatly appreciate it. Thank you.