1

I made a simple Angular app with three routes (home, hello, detail). Home contains long text with scrolling.

After scrolling little bit, click hello or detail link, then click the home link again.

I want to keep it where I left off and avoid scrolling back or making ajax call if any. In other words serve cached page.

Tried various solutions like scrollPositionRestoration:enabled or implement custom routereusestrategy but its not working. Not sure what the issue is? Or if I am totally off.

Any help is appreciated. Thanks

Edit: I was able to get the component state to work using compareObjects code block. Now just need the scrolling to work

surya
  • 1,351
  • 1
  • 13
  • 29
  • Why not save the information on a service? – Owen Kelvin Dec 25 '20 at 11:43
  • @OwenKelvin thanks, that's going to be my fallback solution to save scroll position in service. I am trying to find a built in solution and see why scrollPositionRestoration is not working – surya Dec 25 '20 at 18:27
  • 1
    `scrollPositionRestoration` is for backwards navigation, and for the scroll of the whole page. You can see how it works if you remove the fixed `height` from the `div`, scroll down in the page, change to another route and use your browser's "back" button. See the reference for `scrollPositionRestoration`: https://angular.io/api/router/ExtraOptions#scrollPositionRestoration – Cem Dec 25 '20 at 19:27
  • @Cem you are right, removing height from div worked! Now i need to see if i can do scrolling for inner div – surya Dec 25 '20 at 21:48

0 Answers0