Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.Sign up
Can portals be used for SPA routing? #156
I was directed here by another thread and portals look great! It seems like many use-cases may be covered, but I couldn't find any detail that helps verify if portals can be used for single page application routing.
Many times developers want to just update DOM when a user has accessed some relatively deeper URL in the browser.
Can this be done with portals without replacing all contents of the HTML? I'd like to just replace parts of HTML when navigating to new inset page.
I don't think I see how portals could be used for your use case: it provides a mechanism for smoothly transitioning between frames holding entirely separate documents.
You could achieve what you describe either by using portals and arranging to transfer the state in the rest of your HTML, but more likely you would use a traditional SPA approach (fetching the parts of the HTML that you want from the server with XHR/fetch and updating the DOM yourself).
It's not clear to me how the UA could tell what parts of the DOM you would want replaced, or how much prerendering we could reasonably do if you intend to transplant everything into a separate document.
Oh yeah, what I'm proposing is definitely solved in existing libraries. In fact, I created one of them