Giter Site home page Giter Site logo

Comments (4)

Paratron avatar Paratron commented on May 18, 2024 2

I would implement it like this:

import React from 'react';
import {useRoutes} from 'hookrouter';

import LoadingPlaceholder from './LoadingPlaceholder';

const Page1 = React.lazy(() => import('./page1'));
const Page2 = React.lazy(() => import('./page2'));
const Page3 = React.lazy(() => import('./page3'));

const routes = {
	'/': () => <Page1 />,
	'/about': () => <Page2 />,
	'/contact': () => <Page3 />
}

const MyApp = () => {
	const routeResult = useRoutes(routes);

	return (
		<React.Suspense fallback={LoadingPlaceholder}>
			{routeResult}
		</React.Suspense>
	);
};

Actually waiting is not in favor of the user in this case. The app would "freeze" until the next "pages" components are loaded. You should use suspense instead and actually tell the user: hey, we are loading something here.

from hookrouter.

cevr avatar cevr commented on May 18, 2024

Indeed but I was thinking of something like a loading bar that would appear within the previous route. Something like this

from hookrouter.

Paratron avatar Paratron commented on May 18, 2024

Well, the call to import() returns a promise. What you could do is intercepting the navigation, show a loading bar and wait for the promise to resolve - then finalize the navigation intent.

from hookrouter.

vermakartik avatar vermakartik commented on May 18, 2024

I am having some troubles figuring out the right way of implementing it.

can you provide an example snippet ?

Well, the call to import() returns a promise. What you could do is intercepting the navigation, show a loading bar and wait for the promise to resolve - then finalize the navigation intent.

from hookrouter.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.