Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

nextjs-progressloader

samuhmatos4.1kMIT1.3.0TypeScript support: included

Next.js library to manage navigation between pages/routes with loading animation

nextjs, progressloader, progressbar, next-progress, top-progressloader, nextjs-progressloader, next-loading, loading, Next, Next TopLoader, Next.js, Next.js 13, Nprogress, React, Top Loading Bar, Progressbar

readme

Next Js Progress Loader

Important context: Latter the Next.Js 13 update, router events has ben depreciated and still there's no 'next native resource' to manipulate router events as before. But this lib was build to solve this problem and bring a new way to make the UX/UI better!

Downloads GitHub stars

Install

npm install nextjs-progressloader

yarn add nextjs-progressloader

Basic Usage

Import the animation component:

import { ProgressLoader } from 'nextjs-progressloader';

Usage with app/layout.js for app folder structure

For rendering add <ProgressLoader /> to your return() inside the <body></body> tag of RootLayout():

'use client';
import { ProgressLoader } from 'nextjs-progressloader';

export default function RootLayout({ children }) {
  return (
    <html lang="en">
      <body>
        <ProgressLoader />
        {children}
      </body>
    </html>
  );
}
Learn more about <ProgressLoader />

Advanced Usage

If you would like to render some route with the Load Animation, use <ContainerLink /> component and our custom useRouter() hook to do it:

When render <ContainerLink /> you are required to pass a links prop which is responsible to create all the needed events to work.

And when using useRouter() a event will be emitted based on the function's param.

  • Important and required: To this feature work correctly, the links prop and the function's parameter must be equals.
  • You can render the component how many times you want and anywhere you want, being inside the <body></body>
  • Using the <ContainerLink /> next will identify the routes and will pre-render: verify the documentation

Once the links are defined, you can invoke the route wherever and whenever you want using the nickname or href.

Learn everything about the Usability flow

Example usage

import { useRouter, ContainerLink, ContainerLinkProps } from 'nextjs-progressloader';

const links: ContainerLinkProps["links"] = [
  {
    href: "/",
    nickname: "home",
  },
  {
    href: "/posts",
    nickname: "posts"
  },
  {
    href: "/login",
  },
];

export function ComponentIWantToRender(){
  const router = useRouter()

  function validateSomeThing(){
    // your validation

    //Example
    if(userLogged){
      // calling by the nickname
      router.push("home")
    }else{
      //calling by the route
      router.push("/login")
    }
  }

  return (
    <>
      <ContainerLink links={links} />;

      <button className="bg-red-500" onClick={validateSomeThing}>
        Validating something
      </button>
    </>
  )
}
Learn everything about the Usability flow

Issues

Do you have any suggestions or issue? Please let me know
Check the changelog

changelog

Changelogs

v1.3.0

Added

  • Added Mac support with metakey
  • Added ProgressLoader inside Suspense's React component

v1.2.0

Updated

v1.0.0

Added

  • Added the new and upgraded useRouter() hook. It is possible using all the useRouter() native features with animation (push, replace, back)

Updated

  • changeRoute() function is deprecated, use the new useRouter() hook

v0.1.8

Added

  • Added possibility to add query string to the called route using changeRoute()

Fixed

  • Fixed the event wasn't removed on change route bug

v0.2.1

Fixed

  • Fixed the queryString bug when a route didn't have a dynamic route.

v0.2.0

Added

  • Added the ability to use dynamic routes using {key here}:
    • Passing when is registering the route, ex.:
      {href: "/route/to/{key}", nickname:"route"}
    • Call the route, Ex.:
      changeRoute("route", {
          dynamicRoute: [
              {key: "key", value: "dynamic-route"}
          ]
      })

Updated

  • Validating the url if is valide for using.
  • The params key passed in changeRoute() now has the name queryStrings

v0.1.9

Added

  • Added the ability to open link in a new Tab using then changeRoute()