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.

code splitting of routers?

See original GitHub issue

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
}

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
ItalyPaleAlecommented, Oct 17, 2019

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

1reaction
ItalyPaleAlecommented, Oct 9, 2019

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 😃

Read more comments on GitHub >

github_iconTop Results From Across the Web

Code Splitting with React, React.lazy, and React Router - ui.dev
In this post you'll learn how to increase the performance of your React application by adding code splitting with React.lazy and React ...
Read more >
Routing and Code Splitting in React - Better Programming
In this piece, I'll demonstrate how to use React Router and at the same time take into account performance optimization using route-based code...
Read more >
React Router 6.4 Code-Splitting - Infoxicator.com
The Component and Loader can be code-split into separate files. The Component's javascript bundle and the data fetching start at the same time, ......
Read more >
Code Splitting with React and React Router - Medium
Code splitting has gained popularity recently for its ability to allow you to split your app into separate bundles your users can progressively...
Read more >
Code-Splitting - React
Here's an example of how to setup route-based code splitting into your app using libraries like React Router with React.lazy . import React,...
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