question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Promise and lazy routes...

See original GitHub issue

Looking at yrv router (a good router!) we can see two ways of importing routes:

<Router>
  <Route exact path="/promise" component={import('path/to/other-component.svelte')}/>
  <Route exact path="/lazy" component={() => import('path/to/another-component.svelte')}/>
</Router>

With https://github.com/ItalyPaleAle/svelte-spa-router/blob/master/Advanced Usage.md#async-route-loading we have just the lazy one. Am I correct?

I think it would be useful (and amazing) to have both in svelte-spa-router (three-shaked if we do not use them).

The promise way I think is amazing because I can have a lot of routes and maybe I just need to load immediately just the one I need and after that in background start downloading others.

What do you think about?

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:11 (11 by maintainers)

github_iconTop GitHub Comments

6reactions
ItalyPaleAlecommented, Apr 18, 2020

Thanks for the great discussion. I think y’all are right and it’s time we implement this natively in the router.

@hmmhmmhm let me know if you are able to work on a PR. If you can, I’d greatly appreciate it, but no pressure 😃

I’m scheduling this for 3.0

1reaction
ItalyPaleAlecommented, Sep 6, 2020

There’s currently work being done in #73 to support dynamically-imported routes.

Once that’s implemented, it will be possible to do a lazy loading too, by invoking import('foo.svelte') in your init code in main.js. Subsequent invocations to import, including in async routes as supported by #73, will just return the cached code.

I’ll write some docs on how to do this

Read more comments on GitHub >

github_iconTop Results From Across the Web

Uncaught (in promise): Error: Cannot match any routes. URL ...
I am trying to lazy load the orders module which has two components orders and test. The orders route is working fine but...
Read more >
Lazy Loading Routes | Vue Router
Lazy Loading Routes # ... When building apps with a bundler, the JavaScript bundle can become quite large, and thus affect the page...
Read more >
How To Use Lazy Loading Routes in Angular | DigitalOcean
In this article, you will use lazy loading routes in an Angular ... The dynamic import is promise-based and gives you access to...
Read more >
Lazy Loading Routes using an Observable with the Angular ...
The snippet above uses the loadChildren property in the Route object to lazy load the route using a Promise. This API is defined...
Read more >
Lazy transitions when providing a promise as an argument to ...
It doesn't always seem to work well when passing a promise in to transitionTo , though. When the target route and its parent...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found