Unable to console a pushed history event.state object, always returns 'null'
I'm trying to set up back and forward button navigating on my search results page, to enable going 'back a search' without leaving the page completely.
I'm currently just trying pass an arbitrary object :
history.pushState({word:"this"}, null, "SearchResults" )
.
And listening for window 'popstate' event, then consoling history.state
function displayLastState(){ console.log("back button hit"); console.log(history.state); } window.addEventListener('popstate', displayLastState)However, I only ever get 'null' in the console. I see the URL change to include 'SearchResults' at the end, so I know the pushState is running. Can someone please tell me what I'm doing wrong? BTW the history.pushState is occurring at line 141, and the window.addEventListener() and associated callback are at line 74 and 81. GH:https://github.com/nnall/DevJobs-FEM.git Live:https://main--dynamic-salmiakki-7aaccb.netlify.app/
GitHub
GitHub - nnall/DevJobs-FEM
Contribute to nnall/DevJobs-FEM development by creating an account on GitHub.
0 Replies