Angular: NullInjectorError: No provider for ActivatedRoute! (also Router) — usually a unit test
A component injects ActivatedRoute or Router, but no router providers exist in the injector — typical in unit tests or when the router was not configured.
NullInjectorError: No provider for ActivatedRoute!No provider for ActivatedRouteNo provider for RouterNullInjectorError: No provider for Router!R3InjectorError ActivatedRoute Meaning
In the app, provideRouter(routes) (or RouterModule.forRoot) provides them. In a unit test you must provide them yourself: provideRouter([]), RouterTestingModule, or a fake { provide: ActivatedRoute, useValue: { snapshot: { paramMap } } }.
Common causes
- Unit test without router providers
provideRoutermissing in the application config- Component created outside the router tree
- Using
ActivatedRoutein a service provided in a platform injector - Wrong import of
RouterTestingModule(removed in newer versions)
⚡ Quick fix
- In tests:
provideRouter([])or provide a fake ActivatedRoute - In the app: add
provideRouter(routes) - Avoid constructing router-dependent components manually
Detailed fix by platform
Angular
TestBed.configureTestingModule({ providers: [{ provide: ActivatedRoute, useValue: { snapshot: { paramMap: convertToParamMap({ id: '7' }) } } }] })
Code examples
Faking the route in a test
TestBed.configureTestingModule({
imports: [OrderComponent],
providers: [
provideRouter([]),
{ provide: ActivatedRoute, useValue: { snapshot: { paramMap: convertToParamMap({ id: '7' }) } } },
],
});How to diagnose
- Context — Test or running app?
- Providers — provideRouter present?
- Route data — What does the component read?
🔧 Still not fixed?
Many errors look alike. If the steps above didn’t solve it, one of these is probably what you’re facing:
Similar errors
- Cannot GET /route on refresh Angular (production): Cannot GET /dashboard — 404 when refreshing or opening a deep link
- Karma Disconnected / no captured browser Angular tests: Disconnected, because no message in 30000 ms. / ERROR [launcher]: Cannot start ChromeHeadless
- NG0200 Angular: NG0200: Circular dependency in DI detected for X
Most viewed in Angular
- NG0100 Angular: NG0100: ExpressionChangedAfterItHasBeenCheckedError: Expression has changed after it was checked
- NG8002 Angular: NG8002: Can't bind to 'ngModel' since it isn't a known property of 'input'
- Can't find stylesheet to import Angular (Sass): Error: Can't find stylesheet to import. @import 'variables';
Other ways to find it
Where this error sits
Origin: On your device. Errors that are often confused with or caused by this one (click to open):
🧠 Still stuck? Analyze your error
Paste the full message, response headers or stack trace — we'll detect the platform and point to the most likely cause.
💬 What worked for others
No tips yet — did something else fix this for you?
Share what worked for you
Tips are checked by an editor before they appear. Links are removed.
Report a correction or suggest an improvement
Last updated 15 Oct 2026