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

code splitting of routers? #31

Closed
hmmhmmhm opened this issue Oct 9, 2019 · 5 comments
Closed

code splitting of routers? #31

hmmhmmhm opened this issue Oct 9, 2019 · 5 comments

Comments

@hmmhmmhm
Copy link
Contributor

hmmhmmhm commented Oct 9, 2019

I have recently focused on developing the Svelte project using Parcel.... By the way, I wonder if the code splitting of parcel can be applied to the routes index map of spa router.

import Home from './routes/Home.svelte'
import Book from './routes/Book.svelte'
import NotFound from './routes/NotFound.svelte'

const routes = {
    '/': Home,

    // Might be like this?
    '/author/:first/:last?': async () => await import('./routes/Author.svelte'),

    '/book/*': Book,
    '*': NotFound
}
@ItalyPaleAle
Copy link
Owner

Hi @hmmhmmhm I have not tried this, but it should work.

However, what you need to keep in mind is that the async function would be executed when the route object is defined. So, yes, you'd get code splitting – but all routes would be loaded at the same time, on page load.

If you want true async loading, then a possible way is to add to the router a route whose sole job is to load the Author route asynchronously.

If you want to modify this router to support async route loading, you're welcome to submit a PR :)

@hmmhmmhm
Copy link
Contributor Author

hmmhmmhm commented Oct 9, 2019

I just searched and found a module called svelte-loadable, and I have succeeded in implementing asynchronous loading through this module. I'll check the structure of the svelte spa router, and if possible, I'll do PR. thanks for answer!

@hmmhmmhm
Copy link
Contributor Author

hmmhmmhm commented Oct 16, 2019

https://github.com/hmmhmmhm/svelte-spa-chunk

I maded a async route loading module for svelte-spa-router.
can I add my module to this repo on REAME.MD(Advanced Usage)?

I think it would be more efficient to introduce
a separate extension module than to embed
a module called svelte-loadable into the spa-router.

@hmmhmmhm
Copy link
Contributor Author

@ItalyPaleAle

@ItalyPaleAle
Copy link
Owner

Thanks for that. I like your solution, and I think it looks very elegant. I'm happy to include a note in the Advanced Usage readme. Let's continue in #36

ItalyPaleAle added a commit that referenced this issue Oct 17, 2019
freshteapot pushed a commit to freshteapot/svelte-spa-router that referenced this issue Nov 18, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants