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.

React: routes are not preloaded

See original GitHub issue

Describe 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:closed
  • Created 3 years ago
  • Comments:10 (7 by maintainers)

github_iconTop GitHub Comments

2reactions
anton-karlovskiycommented, Jul 22, 2020

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.

1reaction
anton-karlovskiycommented, Jul 23, 2020

@addyosmani @demianrenzulli cc @ryands17

Hi folks, I think we can close this issue.

Read more comments on GitHub >

github_iconTop 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 >

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