-
-
Notifications
You must be signed in to change notification settings - Fork 107
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
use dynamic routes with wrap #73
Comments
Still not possible, sorry. I ran into some issues when trying to implement that, and it is in the backlog. PRs are welcome :) |
Maybe I can find time to look up about this this this weekend. If I don't work overtime... |
@hmmhmmhm it would be amazing. As writed here: #104: Looking at <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%20Usage.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 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? |
@frederikhors What you said is a different issue from wrap. |
@hmmhmmhm @frederikhors @joshua1 @BogdanDarius (tagging everyone who ever asked about this feature) I finally managed to get a working prototype of this, in the dynamic-import branch. It works by creating the import {wrapAsync} from '../../Router.svelte'
export default {
'/async': wrapAsync(() => import('./Async.svelte')
} (Note that you must use a function definition, such as Then it should just work 😄 The only thing I'd love your input on is on how to handle the "loading" state. Right now, I've created another event called I have a few options I'm considering:
What are your thoughts on the above? I'm leaning towards option 3 as that seems the most idiomatic to this router. But would like to hear your thoughts. I'm also open to suggestions on other ways this can be implemented. |
Awesome! |
Thanks a lot for testing it and confirming it works! Good point. A different loading view for each component was not a requirement I had considered. But it makes sense. Doing that would not be possible with the options above (maybe with 1). It would require people to manually determine the loader to show, for example by using the $location store to know what component will be loaded. The only way to do that in the router would be to use option 5:
|
I like the idea of having it as an argument to |
Thanks @BogdanDarius for the feedback! The dynamic-import branch has been updated and now the @hmmhmmhm @frederikhors what do you think? |
Awesome work. |
Sorry for my delay in replying. Great job, @ItalyPaleAle, as always. I haven't tested it yet because I don't have time right now but I trust and know it will work. Personally I agree with the idea number 5 (passing the loading component as an argument of Example: const routes = new Map()
.set('/home', PageHome)
.set('/async', wrapAsync(() => import('Players.svelte'), LoaderComponent, {loader: props})) Can we do something like that? |
@frederikhors thanks for the feedback! The problem with the syntax you're suggesting is that the |
Can we use an obj like: { LoaderComponent, props } ? Like: const routes = new Map()
.set('/home', PageHome)
.set('/async', wrapAsync(() => import('Players.svelte'), { LoaderComponent, props }) |
It would have to be more like As an alternative, because the signature is getting complicated enough already, I could simply make |
I've updated the (The Thanks a lot for your feedback @frederikhors and @BogdanDarius. I think this will work and I'll merge it into the 3.0-wip branch. This will be the major new release for the router v3, which I plan to finish ASAP :) |
@ItalyPaleAle you said in your PR for Wrap that you would make modifications to take a promise as first parameter for wrap to enable dynamic wrap import. Is this possible now. this seems like the only way to use both features (wrap and preconditions alongside dynamic route loading )
The text was updated successfully, but these errors were encountered: