Movatterモバイル変換


[0]ホーム

URL:


Skip to content
DEV Community
Log in Create account

DEV Community

Fabian
Fabian

Posted on

Add router progress bar in Next Js 14

Github Loading Indicator

Get Started

I struggled to implement a loading indicator in my Next.js 13 and Now.js 14 apps. With the Next.js App router, many progress bar packages became ineffective. But after some research, I found a working package that was updated recently and works perfectly in the Next.js 14 app router.

It doesn't matter if you already have a fully functional Next.js app or are creating a new one. First you need to install thenextjs-toploader package.

npm i nextjs-toploader
Enter fullscreen modeExit fullscreen mode

or

yarn add nextjs-toploader
Enter fullscreen modeExit fullscreen mode

app/layout.tsx or app/layout.jsx

importNextTopLoaderfrom'nextjs-toploader';exportdefaultfunctionRootLayout({children}:{children:React.ReactNode,}){return(<htmllang='en'><body><NextTopLoader/> // Just need to add this line{children}</body></html>);}
Enter fullscreen modeExit fullscreen mode

Customizations

To customize your progress bar you can add these props to yourNextTopLoader and change the values.

<NextTopLoadercolor="#2299DD"initialPosition={0.08}crawlSpeed={200}height={3}crawl={true}showSpinner={true}easing="ease"speed={200}shadow="0 0 10px #2299DD,0 0 5px #2299DD"/>
Enter fullscreen modeExit fullscreen mode
  • color: to change the default color of TopLoader.
  • initialPosition: to change initial position for the TopLoader in percentage, :0.08 = 8%.
  • crawlSpeed: increment delay speed inms.
  • speed: animation speed for the TopLoader inms
  • easing: animation settings using easing (a CSS easing string).
  • height: height of TopLoader inpx.
  • crawl: auto incrementing behavior for the TopLoader.
  • showSpinner: to show spinner or not.
  • shadow: a smooth shadow for the TopLoader. (set tofalse to disable it)
  • template: to include custom HTML attributes for the TopLoader.
  • zIndex: defines zIndex for the TopLoader.
  • showAtBottom: To show the TopLoader at bottom. (increase height for the TopLoader to ensure it's visibility at the mobile devices)

Happy coding :)

Top comments(0)

Subscribe
pic
Create template

Templates let you quickly answer FAQs or store snippets for re-use.

Dismiss

Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment'spermalink.

For further actions, you may consider blocking this person and/orreporting abuse

18 year old fullstack webdeveloper from germany
  • Location
    Germany
  • Joined

Trending onDEV CommunityHot

DEV Community

We're a place where coders share, stay up-to-date and grow their careers.

Log in Create account

[8]ページ先頭

©2009-2025 Movatter.jp