In a recent application, they wanted to store the last url within a page (or area) the user visited.
This codepen shows how to do it:
If you:
- click on
Last Dogs Page
and then selectdog 1
, - then click
Home Page
, - Then if you click
Last Dogs Page
again, the selection ofdog 1
will remain.
It works by listening to when the url changes and checking if the url’s data includes page: "dog"
. If it does, it saves that url.