JS: ERROR Error: Uncaught (in promise): Error: Cannot match any routes. nativescript URL Segment: 'adminTab/default'
JS: ERROR Error: Uncaught (in promise): Error: Cannot match any routes. nativescript URL Segment: 'adminTab/default'
If you are using NativeScript with Angular, you might encounter this error when navigation to a specific page or tab:
ERROR Error: Uncaught (in promise): Error: Cannot match any routes. nativescript URL Segment: 'adminTab/default'
This error message is telling us that the router cannot find a matching route for the specified URL segment.
Possible Causes
- You did not define the route for the specified URL segment
- The route definition is incorrect
- The navigation URL is incorrect
Solution
Make sure that:
- You have defined the route for the specified URL segment in app-routing.module.ts file:
{
path: 'adminTab',
loadChildren: () => import('./admin/admin.module').then(m => m.AdminModule),
canActivate: [AuthGuard],
data: { role: 'admin' }
}
- The route definition is correct. For example, if you are navigating to a tab, make sure you are using the correct syntax:
this.router.navigate(['/adminTab/default']);
- The navigation URL is correct. Double-check that the URL segment matches the route definition.
If you still cannot resolve the issue, you can try debugging by logging the router events:
// import Router and NavigationEnd
import { Router, NavigationEnd } from '@angular/router';
// subscribe to NavigationEnd event
this.router.events.subscribe((event) => {
if (event instanceof NavigationEnd) {
console.log(event.urlAfterRedirects);
}
});
This will log the URL after the navigation is complete. Check if the URL matches the route definition.