For context, I am currently trying to build a really simple webapp that can send requests to my own backend. I use a Client JavaScript object, and the way that I track who is sending what request is with a ticket. The ticket is generated when I send a login request to the API. The way that I am trying to build the website, I should be able to maneuver from page to page while being able to know what my ticket is, as well as some other information that will be stored in other objects.
Here is my question: how do I traverse from page to page (under new paths) while maintaining the same instance of the object? Anytime I go from “/” to “/user”, I think it is using a new DOM so when I call the Client class, the ticket is empty again. Is this something that has a simple solution or is it impossible to persist data in object between pages? If that is the case, how do websites normally keep track of this kind of information between pages? I can hardly imagine that the solution is to “store” the ticket in the URL as a parameter and then use that to send a request to the backend for any of the other information that I had in the previous page.
Any help will be very appreciated 🙂
Thank you!
I tried to create the Client object in a separate script and then call it within the new pages whenever I needed to, however, every time I did, it would treat it as if it was the first time I was creating the object.
As a temporary solution, I created a page that holds all of the views that I need on the website, and anytime it switches pages, it makes the current one hidden, and shows the ones that are needed. I know this is probably not a secure/ efficient solution but it is all I could figure out at the moment because this way, I stay on the same ejs script and the Client object persists through the pages.
1