React: routes are not preloaded
See original GitHub issueDescribe the bug Routes are not preloaded if they are configured in the following manner:
To Reproduce
- Create routes
import { withQuicklink } from 'quicklink/dist/react/hoc.js'
export const routes = {
home: {
path: '/',
element: withQuicklink(React.lazy(() => import('pages/Home'))),
},
about: {
path: 'about',
element: withQuicklink(React.lazy(() => import('pages/About'))),
},
contact: {
path: 'contact',
element: withQuicklink(React.lazy(() => import('pages/Contact'))),
},
}
- Add those to
react-router
import { useRoutes } from 'react-router-dom'
export const AppRoutes = () => {
const renderRoutes = useRoutes(
Object.values(routes).map((route) => ({
path: route.path,
element: <route.element />,
}))
)
return renderRoutes
}
Expected behavior Route chunks should be preloaded.
Version:
- OS w/ version: [Linux]
- Browser w/ version [e.g. Chrome 81]
Issue Analytics
- State:
- Created 3 years ago
- Comments:10 (7 by maintainers)
Top Results From Across the Web
react router preload data from multiple components with a ...
The header is first loaded after being redirect from /login to /portal . I have setup in redux a global loader, which basically...
Read more >Comments on the v6 preload API · Issue #7200 - GitHub
This works with react router 6 but does not preload (e.g. load on mouseover or so). You can show a loading indicator before...
Read more >File-based routing with React Router — Pre-loading
The prefetch prop will be a boolean , if true the route will pre-load once the Link component is at the browser viewport....
Read more >React Lazy: a take on preloading views - Maxime Heckel's Blog
React Router comes with a pretty handy method called matchPath which for a given path will return true if the path passed in...
Read more >Code splitting and preloading React routes with Webpack
An introduction to setting up code splitting on React routes using Webpack with several ways of managing preloading.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Hi @ryands17
We created this project for the same use case. https://github.com/anton-karlovskiy/cra-hover-prefetch Could you please check it and give me feedback? Thank you.
It was ejected create-react-app for configuring webpack-route-manifest. Probably it was setup with the old webpack-route-manifest which does not allow us to use
window.__rmanifest
.@addyosmani @demianrenzulli cc @ryands17
Hi folks, I think we can close this issue.