Well, I think setting an example would take a lot of time, but I've done something like that and can help you with logic.
First you need any form of a server language, in the case of PHP you will have to use .htaccess . With it you have to create a rule that redirects all the URL's to the main file, because if the user refreshes the page or enters the URL manually, it will not be considered a pushState
, so it will redirect.
After that you have to create a function that reads the normal URL with the attributes of document.location
. This function should read the URL and be responsible for executing each action per URL, such as opening a modal for example.
Once the function is created, it must be executed at page load and at each URL exchange with pushState
, so you can call it at events window.onload
and window.onpopstate
.
Note:
1 - If the behavior is better, you can execute the function call as soon as the DOM is ready to loaded.
2 - The pushState
to which I referred is the function to change the URL if you redirect the page. '
The logic I used was this.