I am developing an application in Angular 4. When I am trying to write routes for a feature module, I am getting an error as Error: Cannot match any routes.
Here's the routes code I have used:
const COURSE_ROUTES: Routes = [
{path: '', redirectTo: '/', pathMatch: 'full'},
{path: ':name', component: CourseComponent},
{path: '**', component: ErrorComponent}
];
Routing is working fine and going to the CourseComponent when the route is something like course/angular or course/some-course-name but when I try to inject some XSS script into the same route, such as
course/<script>alert('0wn3d')</script>,
its throwing an error as
ERROR Error: Uncaught (in promise): Error: Cannot match any routes. URL Segment: ''0wn3d'' Error: Cannot match any routes. URL Segment: ''0wn3d'
though I have written a wild card entry for error routes. I have tested that the
{path: '**', component: ErrorComponent}
is showing the 404 error page, by removing the
{path: ':name', component: CourseComponent}
and running the app with some random url like course/some-course
Please help me resolve this. Thanks in advance.
It is not possible to have / as the root URL.
{path: 'some-name:name',pathMatch: 'full',component:CourseComponent}
Documented here

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With