0

I am currently using a canActivate-service for my angular parent route and therefore for all the childroutes. looks like that for example

const routes: Routes = [
{
path: '',
canActivate: [ServiceWhichShouldRunEvery10Minutes],
runGuardsAndResolvers: 'always',
children: [
  {
    path: routeA,
    component: a,
  },
  {
    path: routeB,
    pathMatch: 'full',
    component: b,
  },...

canActivate-method

  async canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Promise<boolean | UrlTree> {
// condition that i want to check every 10 minutes
}

How do I ensure, that this canActivate service will be fired every 10 minutes? Thanks in advance, any help is appreciated

s.stkvc
  • 127
  • 1
  • 2
  • 12
  • 2
    I guess this is not possible with `canActivate` because this is triggered only on navigation, and there is no possibility I know to trigger it manually. Why does it need to be inside `canActivate`? Maybe place it in app component instead? – JSON Derulo Dec 02 '21 at 12:12
  • 2
    Yeah, such a behavior doesn't belong to the routing tasks. Use a service with for example an interval to perform what you need to do every 10 minutes. or if only needed in one component, do it there. For future though if needed elsewhere service is a good choice :) – AT82 Dec 02 '21 at 12:48

0 Answers0