I know how to implement a function that goes back to the previous page and takes a certain variable when a certain button is clicked.
// The 2 at the end of the url is the variable I want to pass.
<button onclick='location.href="a link that prev page has/2"'> Back to prev page </button>
However, I do not know how to pass a specific variable while returning to the previous page when the back button, which is implemented by default in the Chrome browser, is pressed.
I am trying to get the variable passed from the previous page I returned to and use it. What should I do when I click the browser back button?
If there are different functions to be implemented depending on the browser, it would be thankful if you could tell us about it as well.
+) Each page is implemented as a separate ejs file.
if you want to reload the previous page and know the path i would rather construct the link
const new_location = location.origin + '/page'
const new_url = new URL(new_location)
new_url.searchParams('param1','value')
location = new_url
then node side you can use
const {param1} = req.query