Well, I think setting an example would take a long time, but I’ve done something like this and I can help you with logic.
First you need any form of a server language, in the case of PHP you will have to use the .htaccess. With it you have to create a rule that redirects all URL’s to the main file, because if the user refreshes the page or enters the URL manually, will not be considered a pushState
, so will redirect.
After that you have to create a function that reads the URL normally with the attributes of document.location
. This function must read the URL and will be responsible for executing each action referring to the URL, like opening a modal for example.
After creating the function, it should be executed on page loading and on each URL exchange by pushState
, for this you can call her in the events window.onload
and window.onpopstate
.
Observing:
1 - If the behavior is better, you can call the function as soon as the DOM is ready to load.
2 - The pushState
which I was referring to is the function to change the URL if redirecting the page.`
The logic I used was this.
Question... why, reason or circumstance has to change the URL when opening the modal?
– Tafarel Chicotti
I updated the post with an exact example, check out friend.
– Raank