# Angular: NullInjectorError: No provider for ActivatedRoute! (also Router) — usually a unit test

**Code:** `NullInjectorError: No provider for ActivatedRoute!` · **Category:** Angular · **Seen on:** Angular, TypeScript

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.

## 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?

---
Source: [WhatIsMyError](https://whatismyerror.com/errors/angular/no-provider-for-activatedroute)
