Implementing shouldAttach of RouteReuseStrategy only on navigating from a specific route

I am trying to store path that I will be reusing it when I navigate from one particular route. Goal is to restore the stored path only on navigating from a specific button and not restoring on other navigation like top menu navigation.

There are 3 components as mentioned below.

1) HomeComponent – Once user logged in, this is the landing component.

2) SearchComponent – User navigates here from HomeComponent through top menu. This is where the user searches multiple criteria (The component I would like to store and reuse). The search results are displayed.

3) DetailsComponent – From search results, the user navigates here using the edit icon of each row. The details are displayed here. I have a back button here which takes the user to SearchComponent. I want to restore the SearchComponent only when the user navigates using this back button. There is also a top menu, using which the user can go to the SearchComponent. In this case I don’t want to restore the SearchComponent.

I have gone through this link and able to store and restore the SearchComponent. The problem is, no matter from where I navigate to the SearchComponent, the component is getting restored. I want to restore it only when the user clicks the back button from the DetailsComponent. I do not want to restore the SearchComponent while navigating from the top menu. Please find my code below.


export class AppRoutingCache implements RouteReuseStrategy {
  routesToCache: string[] = ['home/search'];
  storedRouteHandles = new Map<string, DetachedRouteHandle>();

  shouldDetach(route: ActivatedRouteSnapshot): boolean {
    return this.routesToCache.indexOf(route.data["key"]) > -1;
  }

  store(route: ActivatedRouteSnapshot, handle: DetachedRouteHandle): void {
    this.storedRouteHandles.set(route.data["key"], handle);
  }

  shouldAttach(route: ActivatedRouteSnapshot): boolean {
    return this.storedRouteHandles.has(route.data["key"]);
  }

  retrieve(route: ActivatedRouteSnapshot): DetachedRouteHandle {
    return this.storedRouteHandles.get(route.data["key"]);
  }

  shouldReuseRoute(future: ActivatedRouteSnapshot, curr: ActivatedRouteSnapshot): boolean {
    return future.routeConfig === curr.routeConfig;
  }
}

Thanks in advance

Source: New feed
Source Url Implementing shouldAttach of RouteReuseStrategy only on navigating from a specific route