It’s not possible to change the URLs without braking the correct function of PhotoSwipe. The URL is used for a single image. You can use that URL to open the image using the lightbox, nothing else. Just replacing the URL in the URL bar with something else which does not represent the currently displayed image but opens a completely different page makes no sense at all.
The URLs are generated inside PhotoSwipe when an image is displayed in the lightbox. gid
and pid
are the ID of the image group and the image itself which is currently displayed. The frontend script also parses the URL to get the parameters from gid
and pid
so it can tell PhotoSwipe to open the lightbox using this specific image.
It may be possible to use “/page/theansweris42” instead of “/page/#&gid=1&pid=12” in the URL when opening an image (as long as the browser supports history.pushState()
or history.replaceState()
and this is not blocked for security reasons), this could be achieved by modifying PhotoSwipe to accept an URL parameter for each image in the collection to be used.
However – the real problem starts when someone wants to open such an URL. What should happen, if someone opens “/page/theansweris42″? In this case the URL /”page/theansweris42” has to be recognized by the frontend script as instruction to initialize and open a PhotoSwipe lightbox. So this means, you also need some kind of mapping on the server, that “/page/theansweris42” is not just some page, but refers to a single image inside another page which has to be used instead.
So – the whole thing would involve a lot of technical challenge and I don’t see the point what you want to achieve with this. The whole idea of the URL parameters is, that they start with “#”, so the browser will still load the page where the image is located and then the frontend script detects, that an image should be opened on this page.
For another project I did modify the URL pattern to be “#bild-” followed by the number:
https://fahrradzukunft.de/29/wider-den-konsum/#bild-2
-
This reply was modified 4 years, 10 months ago by
Arno Welzel. Reason: Typo