Display a loading indicator with the shortest possible delay whenever utilizing the React Router v6 Link functionality

Integrate React and Router v6

App.tsx:

const Page1 = lazy(() => pMinDelay(import('./views/Page1'), 500))
const Page2 = lazy(() => pMinDelay(import('./views/Page2'), 500))

return (
      <Suspense fallback={<Loading/>}gt;
          <Routes>
            <Route path='/page1' element={<Page1/>}/>
            <Route path='/page2' element={<Page2/>}/>

Navigation:

<Link to='/page1'>Go to Page 1</Link>
<Link to='/page2'>Go to Page 2</Link>

Upon initial visit to URL /page1, the loading with 0.5s delay functions correctly, but subsequent navigations do not trigger the loading and delay.

I am seeking a solution to consistently display a loading spinner with minimal delay when navigating using /page1 and /page2.

Using <Link reloadDocument ..> is not suitable for my application as it would result in a full app refresh.

Answer №1

You have effectively separated page 1 and page 2 from your primary bundle, resulting in them being loaded only when necessary - avoiding double loading.

If you still prefer waiting for a moment, consider creating a personalized hook such as useTimeout within your component. This allows for multitasking while waiting.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Could the slow loading time of the React site be attributed to an overload of static assets?

As a ML professional diving into frontend development, I have recently incorporated various fixed assets such as images into the assets folder for React. However, I've noticed that my website is running slower than expected. Do you believe that these ...

Having trouble with mongoose-paginate and react using material-ui's TablePagination component? Encountering issues where the second page onwards does not render after

I am still learning my way around React, and I believe there is a crucial component missing in this particular React setup. Any assistance leading to a solution will be greatly appreciated. The Functionality I'm Striving For Here - I aim to incorpora ...

Due to high activity on the main thread, a delay of xxx ms occurred in processing the 'wheel' input event

While using Chrome version: Version 55.0.2883.75 beta (64-bit), along with material-ui (https://github.com/callemall/material-ui) version 0.16.5, and react+react-dom version 15.4.1, an interesting warning message popped up as I scrolled down the page with ...

Implementing Asynchronous Rendering in React Router 4

I've been working with React Router 4 and trying to implement Redirect(Auth) following a guide. However, I'm facing an issue with rendering based on the promise returned by an AJAX call. It seems like my rendering logic inside the promise is not ...

Error message encountered with React.js and Next.js: Attempting to iterate through a null object, resulting in a TypeError (property Symbol(Symbol.iterator

Having trouble accessing state's values using [...state_name,{}]. I'm facing an issue while trying to implement this algorithm for a dynamic menu. The data is fetched from the List action of the useFetch method. The data retrieval is successful ...

Referring to TypeScript modules

Consider this TypeScript code snippet: module animals { export class Animal { } } module display.animals { export class DisplayAnimal extends animals.Animal { } } The objective here is to create a subclass called DisplayAnimal in the dis ...

What is the process for retrieving the address of the connected wallet using web3modal?

I've been working on an application using next.js and web3. In order to link the user's wallet to the front-end, I opted for web3modal with the following code: const Home: NextPage = () => { const [signer, setSigner] = useState<JsonRpcSig ...

A different approach for dynamically displaying React components sourced from an API

As I develop a website using Next.js/React that pulls in content from Strapi CMS, my goal is to create a dynamic page template for news articles. The aim is to empower content editors by giving them the flexibility to choose the type of content they wish t ...

Guide on setting component state according to rows selected in Material UI table

Seeking guidance to assist a learner with this task. The Project at Hand I am working on creating a form with 2 inputs: A text field for patient email An array generated by selecting table rows My goal is to update the component state with the values ...

Tips for personalizing the Material UI autocomplete drop-down menu

I'm currently working with Material UI v5 beta1 and I've been attempting to customize the Autocomplete component. My goal is to change the Typography color on the options from black to white when an item is selected. However, I'm struggling ...

Error: The function setEmail is not defined. (In 'setEmail(input)', 'setEmail' is not recognized) (Cannot utilize hooks with context API)

App.js const[getScreen, showScreen] = useState(false); const[getEmail, setEmail] = useState(""); <LoginScreen/> <LoginContexts.Provider value={{getEmail,setEmail,getScreen,showScreen}}> {showScreen?<Screen2/>:<LoginScre ...

node.js + typescript How can we access instances from methods?

Following a server rebuild, the compiler creates an instance in the included API controller as shown below: NewController.ts import express = require("express"); import INew = require("../interface/INew"); import New ...

How can a mock document be utilized in a unit test for an imported TypeScript dependency?

To effectively unit-test a legacy TypeScript class, I am seeking ways to mock the document object. The class has dependencies on another class (View.ts), which in turn relies on a 3rd party module that further depends on the existence of the document. The ...

The KeyValuePair<string, Date> type in Typescript cannot be assigned to the KeyValuePair<number, string> type

I encountered the following issue: An error occurred stating that Type 'KeyValuePair<string, Date>' is not assignable to type 'KeyValuePair<number, string>'. Also, it mentioned that Type 'string' is not assignab ...

Failure of React Library in Production Mode on Webpack 4

Encountering an issue while trying to compile my react library in mode: production. After importing the library into another application, the following error message is displayed: Uncaught TypeError: Cannot set property props of #<TWithProps> which ...

Adding TH into a TABLE in Angular 2 by verifying TD elements

I am seeking a way to automatically generate thead and th, using td in the template : <Datatable> <tr #lineSelected *ngFor="let subscription of results"> <td nameColumn="Nom">{{subscription.name}}</td> <td n ...

iisnode ran into a problem while handling the request. Error code: 0x6d HTTP status code: 500 HTTP subStatus code: 1013

Currently, I am working on a web application using ReactJS for the frontend and Express for the backend. My deployment platform is Azure. In order to verify that my requests are being processed correctly, I decided to conduct two API tests. The first tes ...

Tips on transforming Angular 2/4 Reactive Forms custom validation Promise code into Observable design?

After a delay of 1500ms, this snippet for custom validation in reactive forms adds emailIsTaken: true to the errors object of the emailAddress formControl when the user inputs [email protected]. https://i.stack.imgur.com/4oZ6w.png takenEmailAddress( ...

integrating the power of Next.js with Keystone.js

I attempted to integrate nextjs with keystone js in order to utilize reactjs for the frontend and keystonejs as a CMS. However, I encountered issues as it did not work as expected. Despite following a tutorial where it worked flawlessly, I am unsure why it ...

Ways to encourage children to adopt a specific trait

Let's discuss a scenario where I have a React functional component like this: const Test = (props: { children: React.ReactElement<{ slot: "content" }> }) => { return <></> } When a child is passed without a sl ...