I have a route guard that needs to be configured. On some route we want to check if our user client
is ready, on some others we want to check if our team client
is ready etc.
I've my route guard that looks like this
@Injectable({
providedIn: 'root'
})
export class ClientReadyGuard implements CanActivate, CanActivateChild {
constructor(
private clientName: string,
private router: Router ,
private apolloState: ApolloStateService,
) {
debugger;
}
canActivate(...) {
// do things with clientName
}
and from this guard I'd like to have multiple guards: one that protects with clientName
'all-users', one with 'user', one with 'team', and so on.
To have :
canActivate: [
AllUserClientReadyGuard,
UserClientReadyGuard,
TeamClientReadyGuard,
]
To do so I tried with injection token with no luck; (NullInjectorError: No provider for InjectionToken router token!
).
export const ROUTER_TOKEN = new InjectionToken<Router>('router token');
export const APOLLO_STATE_TOKEN = new InjectionToken<ApolloStateService>('apollo state token');
export const UserClientReadyGuard = new InjectionToken<ClientReadyGuard>(
'user client ready guard',
{
providedIn: 'root', factory: () => new ClientReadyGuard(
USER_CLIENT,
inject(ROUTER_TOKEN),
inject(APOLLO_STATE_TOKEN),
)
}
);