I have a component in Angular which allows the users to perform searches (handled in backend). The backend returns a list of objects based on the query params and the Angular component populates a table to see the result. The user can click on a row to navigate to another route to see the details of the object.
I want to restore the status os the search (values of the search, page of the table, etc) when the user clicks on the Previous Page of the browser. After some research, I have found an approach that consist on:
- When the user is searching and navigating over the results, store the status in a service.
- Then, when the user clicks see the details and click on the Previous Page, detect it in the onInit mehtod of the component that manages the Search and restore the status using the service.
The problem is that in order to detect the onPopState, I have to implement another complex service (Change component attribute in location.onPopState() callback).
Is there any other simpler approach to achieve this search restore in Angular?