4 ms·
I think the author's objections can all be addressed by using history.pushState() and treating the modal window like navigation to a subpage/route (in an SPA-st
by ptx 3y ago
I think the author's objections can all be addressed by using history.pushState() and treating the modal window like navigation to a subpage/route (in an SPA-style app). This way the modal will have a URL, so it can be bookmarked, can be opened in a new tab (if it's opened through a link) and the back button will work (closing the modal).
- roblh 3y agoThis works, except when it doesn’t. I’m not sure about react, but Vue router has some funny and unintuitive interactions when you do this which will often result in unnecessary page reloads, either when you push state or when the back button pops it again. Maybe react behaves better but my experience with it has made me not want to directly mess with history unless I have a particularly good reason to.
- ptx 3y agoIt seemed to work well in Angular in the tiny app where I tried it, but to be clear I didn't directly mess with the history API – I used the navigation mechanisms of the Angular framework to manage this. Calling the browser history API directly could probably confuse the framework.
- aflukasz 3y ago> and the back button will work (closing the modal). Which opens a whole new can of worms! What is the meaning of pressing "back" when modal window is shown? Is it "cancel"? What if I already changed something within the modal? What if "back" causes losing some input within the modal? Should we... show another modal for confirmation of going back? Same with navigation via "back"/"forward" into a modal (which is now present on the history stack) - if this was modal with some action... can I execute it again? Did I just execute it by navigating into it?