Angular Routing NotFoundError
Angular's router throws errors or shows blank pages when routes don't match. This commonly happens with deep links, page refreshes, and lazy-loaded modules.
Wildcard Route for 404
Without a wildcard route, unmatched URLs show a blank page:
const routes: Routes = [
{ path: '', component: HomeComponent },
{ path: 'about', component: AboutComponent },
// This MUST be last
{ path: '**', component: NotFoundComponent }
];Server-Side 404 on Refresh
When users refresh on /about, the server looks for a file at /about/index.html and returns 404. Configure your server to serve index.html for all routes:
# Nginx
location / {
try_files $uri $uri/ /index.html;
}Lazy-Loaded Module Not Found
// Error: Cannot find module './admin/admin.module'
// Check the path is correct:
const routes: Routes = [
{
path: 'admin',
loadChildren: () => import('./admin/admin.module').then(m => m.AdminModule)
},
// Standalone component (Angular 15+)
{
path: 'settings',
loadComponent: () => import('./settings/settings.component').then(c => c.SettingsComponent)
}
];Hash Location Strategy
For environments where server-side routing isn't configurable:
import { HashLocationStrategy, LocationStrategy } from '@angular/common';
bootstrapApplication(AppComponent, {
providers: [
{ provide: LocationStrategy, useClass: HashLocationStrategy }
]
});URLs become /#/about instead of /about, so the server always serves index.html.
Bugsly captures client-side navigation errors in Angular, including the attempted route and the router state at the time of failure.
Try Bugsly Free
AI-powered error tracking that explains your bugs. Set up in 2 minutes, free forever for small projects.
Get Started FreeRelated Articles
Vue.js Debugging Tips for Faster Development
Essential Vue.js debugging techniques including DevTools usage, reactivity debugging, composition API inspection, and common pitfall solutions.
Read moreFix Load Balancer Error in PHP
Resolve PHP application errors behind load balancers including $_SERVER variables, session handling, and file upload proxying.
Read moreFix Cache Error in Haskell
Learn how to fix the Cache error in Haskell. Step-by-step guide with code examples and solutions. Quick, practical guide for developers.
Read moreFix NotFoundError in .NET When Deploying
Resolve deployment-specific file and assembly not found errors in .NET, covering Docker multi-stage builds and Azure App Service issues.
Read more