Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can portals be used for SPA routing? #156

Closed
mkay581 opened this issue Aug 18, 2019 · 4 comments

Comments

@mkay581
Copy link

commented Aug 18, 2019

Hello!

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.

  1. User goes to mysite.com
  2. index HTML loads
  3. User clicks on a link to take them to mysite.com/about-us
  4. Application replaces parts of index HTML in DOM with "About Us" html

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.

@jeremyroman

This comment has been minimized.

Copy link
Collaborator

commented Aug 19, 2019

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.

@mkay581

This comment has been minimized.

Copy link
Author

commented Aug 24, 2019

Yeah, I think what I'm looking for is route mapping: the ability to assign a portal or inset to a requested URL in an SPA. This is what could possibly determine what parts of the DOM would be replaced. Similar to what third-party libraries like react-router and vue-router do.

@jeremyroman

This comment has been minimized.

Copy link
Collaborator

commented Aug 29, 2019

It's not obvious to me what portals would add to those use case over the existing libraries in the space, especially if the use case involves inserting and rendering new (or at least newly adopted) DOM.

@mkay581

This comment has been minimized.

Copy link
Author

commented Aug 29, 2019

Oh yeah, what I'm proposing is definitely solved in existing libraries. In fact, I created one of them 😉 . I guess I was just hoping that portals would eliminate having to rely on existing libraries for the use case. But I think my initial question is answered now so will close this issue. Thanks for the information!

@mkay581 mkay581 closed this Aug 29, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.