Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular 4 throwing Cannot match any routes error with XSS script in URL

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.

like image 781
starlight Avatar asked Dec 04 '25 14:12

starlight


1 Answers

It is not possible to have / as the root URL.

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

Documented here

enter image description here

like image 122
Aravind Avatar answered Dec 07 '25 04:12

Aravind



Donate For Us

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