-
Notifications
You must be signed in to change notification settings - Fork 156
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
Guidance on lazy route loading? #411
Comments
I've had this same question for quite a while too.
My plan is to move to |
I just used I followed instructions in this PR : #372 I had to adjust things to make it work with TS & my non-default exported components, but in the end I have :
Here is my implementation : import { Router } from 'preact-router'
import { Suspense, lazy } from 'preact/compat'
import { useState } from 'preact/hooks'
import { AppLoader } from './components/app-loader'
import { PageError } from './pages/page-error'
import { PageHome } from './pages/page-home'
type Component = typeof PageHome
const AsyncPageSearch = lazy<Component>(() => import('./pages/page-search').then(({ PageSearch }) => ({ default: PageSearch })))
const AsyncPageSettings = lazy<Component>(() => import('./pages/page-settings').then(({ PageSettings }) => ({ default: PageSettings })))
export function App () {
const [isLoading, setLoading] = useState(true)
return (
<>
<Suspense fallback={<AppLoader isLoading />}>
<Router>
<PageHome path="/" />
<AsyncPageSearch path="/search/:input" />
<AsyncPageSettings path="/settings" />
<PageError code="page-not-found" default />
</Router>
</Suspense>
<AppLoader isLoading={isLoading} />
</>
)
} Hope this will help some of you 👍 Happy new year |
@Shuunen works like charm! |
not work for me 😭 |
I wanted to follow up on some of the discussion on lazy route loading. Right now, the preact-async-route package is deprecated, saying to use Suspense and lazy. However, some of the discussion on the pull request here discourages the use of Suspense and lazy for this purpose.
Is there a recommended pattern for achieving lazy route loading?
The text was updated successfully, but these errors were encountered: