NullInjectorError: No provider for ActivatedRoute! Angular Origin: On your device Last updated 15 Oct 2026

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.

Exact message you may see NullInjectorError: No provider for ActivatedRoute!No provider for ActivatedRouteNo provider for RouterNullInjectorError: No provider for Router!R3InjectorError ActivatedRoute
Seen on: Angular TypeScript

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
  • provideRouter missing in the application config
  • Component created outside the router tree
  • Using ActivatedRoute in a service provided in a platform injector
  • Wrong import of RouterTestingModule (removed in newer versions)

⚡ Quick fix

  1. In tests: provideRouter([]) or provide a fake ActivatedRoute
  2. In the app: add provideRouter(routes)
  3. Avoid constructing router-dependent components manually

Detailed fix by platform

Angular

  1. TestBed.configureTestingModule({ providers: [{ provide: ActivatedRoute, useValue: { snapshot: { paramMap: convertToParamMap({ id: '7' }) } } }] })

Code examples

Faking the route in a test

typescript
TestBed.configureTestingModule({
  imports: [OrderComponent],
  providers: [
    provideRouter([]),
    { provide: ActivatedRoute, useValue: { snapshot: { paramMap: convertToParamMap({ id: '7' }) } } },
  ],
});

How to diagnose

  1. Context — Test or running app?
  2. Providers — provideRouter present?
  3. 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:

Where this error sits

Origin: On your device. Errors that are often confused with or caused by this one (click to open):

Cannot GET /route on refresh — Angular (production): Cannot GET /dashboard — 404 when refreshing or opening a deep link (Angular)Cannot GET /route on …Karma Disconnected / no captured browser — Angular tests: Disconnected, because no message in 30000 ms. / ERROR [launcher]: Cannot start ChromeHeadless (Angular)Karma Disconnected / …NG0200 — Angular: NG0200: Circular dependency in DI detected for X (Angular)NG0200NG0201 — Angular: NG0201: No provider for X found in NodeInjector (Angular)NG0201NG0203 — Angular: NG0203: inject() must be called from an injection context such as a constructor, a factory function, a field initializer or a function used with runInInjectionContext (Angular)NG0203NG04002 — Angular: NG04002: Cannot match any routes. URL Segment: 'x' (Angular)NG04002NG04014 — Angular: NG04014: Invalid configuration of route 'x': one of the following must be provided: component, loadComponent, redirectTo, children or loadChildren (Angular)NG04014NullInjectorError — Angular: NullInjectorError: No provider for X! (Angular)NullInjectorErrorNullInjec…

Explore the map of this error Full error map →

🧠 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.