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

SPA Router #3314

Closed
natemoo-re opened this issue May 22, 2023 · 3 comments
Closed

SPA Router #3314

natemoo-re opened this issue May 22, 2023 · 3 comments
Labels
add new content Document something that is not in docs. May require testing, confirmation, or affect other pages. merge-on-release Don't merge this before the feature is released! (MQ=approved but WAIT for feature release!) minor-release For the next minor release; in the milestone, "merge queue" when approved by Sarah!

Comments

@natemoo-re
Copy link
Member

Needs

Note that this feature will be released as experimental at first.

The config reference page will include details on about how to enable this feature.

This might require some restructuring of other docs pages that mention MPA vs SPA as general concepts.

How it works

API is being finalized, but will likely be configured globally in the astro.config.mjs file.

defineConfig({
  router: 'spa'
})

This will enhance all <a> tags to perform a soft navigation rather than a full page reload.

Individual <a> tags can use data- attributes to control specific behavior.

  • <a data-router-ignore> will skip SPA navigation and perform a traditional page load
  • <a data-router-noscroll> will not scroll to the top of the page upon navigation
  • <a data-router-keepfocus> will not reset focus upon navigation

Reference

Although the implementations are quite different, SvelteKit has similar behavior. Their Link Options documentation could be useful conceptual reference.

@NaCoLiu
Copy link

NaCoLiu commented May 24, 2023

I think it is necessary to introduce an export router as a configuration file to control routing, rather than using the default Astro routing. for example

export const router =<AstroRouterType[]> [
 {
   name:'Page',
   path:'/page',
   render: ()=>import('*.astro or tsx')
 }
]

Also, add a label similar to routing view to the layout to support the main body of routing switching.

@sarah11918 sarah11918 added merge-on-release Don't merge this before the feature is released! (MQ=approved but WAIT for feature release!) add new content Document something that is not in docs. May require testing, confirmation, or affect other pages. labels May 25, 2023
@gvkhna
Copy link

gvkhna commented Jun 1, 2023

Is the idea to handle form submissions as well? I think that’s the biggest oversight most solutions make, basically leaving the rigamarole of handling to the dev. Turbo handles form submissions, it would be great to see that as well.

@sarah11918 sarah11918 added the minor-release For the next minor release; in the milestone, "merge queue" when approved by Sarah! label Jun 22, 2023
@delucis
Copy link
Member

delucis commented Jul 27, 2023

Closing until we have the next implementation PR for this proposal.

@delucis delucis closed this as completed Jul 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
add new content Document something that is not in docs. May require testing, confirmation, or affect other pages. merge-on-release Don't merge this before the feature is released! (MQ=approved but WAIT for feature release!) minor-release For the next minor release; in the milestone, "merge queue" when approved by Sarah!
Projects
None yet
Development

No branches or pull requests

5 participants