Great suggestion, thanks! I was so focused on getting the history to work that using a global variable for state didn’t even occur to me. Is it safe to store that variable in a client module?
Knowing what I know now, I completely understand why back & forward button functionality is not built in to Anvil - it’d be ridiculously complex to support it out of the box for all apps. Storing session state in window.history.state is a great workaround though - with that you can detect back/forward events and respond accordingly. As an added bonus, I was also able to link in-app nav buttons to the browser history by calling a js method for window.history.back()
or window.history.forward()
. Pretty cool.
I’m going to edit the thread name to make it easier for others to find. “Accessing javascript listeners from app” isn’t a good description - I was really asking about browser history support. (@meredydd - Feel free to change it back or edit it to something else.)