0
votes

Is there any way to prevent resolve on router if only parameters on that router are changed?

For example, I have this route config.

{path:'home/:status', component:HomeComponent,pathMatch:'full',resolve:{ actionList : HomeActionListResolve}}

The resolve here returns full data set and the component just needs to filter the data based on status like (active, completed, etc)parameter.

What i am trying to achieve is that, if the user is landing on this URL for first time, then resolve should be called, so that it can fetch data.

But if user is changing only status, then resolve should not be called OR even if it is called, then it should not make HTTP request to get the same data again and again.

Can someone please suggest a way to achieve this?

Thanks for the help in advance.

1
are you saving the status info somewhere in service - Rahul Singh
@RahulSingh, No I am not storing. It will be appended in the URL itself and component will retrieve it and set it a property for usage. - Sameer K

1 Answers

1
votes
@Injectable()
export class ResolveFactory implements Resolve<any> {

  url: string[];

  constructor() {

  }

  resolve(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<any>|Promise<any>|any {
    // get the snapshot from activatedroutesnapshot
    let urlStatus= route.url[0].path; 
    or
    let urlStatus = state.url; 

    if(url.contains(split url to get the status){
         return false;
      } else {
        do your work call service and add the status to the URL[] in Resolve
      }
    }
  }