Next progress bar
NProgress integration on next.js compatible with /app and /pages folders
Table of Contents
Getting started
Install
npm install --save next-progress
npm install next-progress-bar
or
yarn add next-progress-bar
Import
Import it into your /pages/_app(.js/.jsx/.ts/.tsx) or /app/layout(.js/.jsx/.ts/.tsx) folder
import NextProgress from 'next-progress';
Use
<ProgressBar />
Exemple with /pages/_app
JavaScript
import ProgressBar from 'next-progress-bar';
export default function App({ Component, pageProps }) {
return (
<>
<Component {...pageProps} />
<ProgressBar
height="4px"
color="#fffd00"
options={{ showSpinner: false }}
shallowRouting
/>
</>
);
}
TypeScript
import type { AppProps } from 'next/app';
import ProgressBar from 'next-progress-bar';
export default function App({ Component, pageProps }: AppProps) {
return (
<>
<Component {...pageProps} />
<ProgressBar
height="4px"
color="#fffd00"
options={{ showSpinner: false }}
shallowRouting
/>
</>
);
}
Exemple with /app/layout
JavaScript
First approach in a use client layout
'use client';
import ProgressBar from 'next-progress-bar';
export default function RootLayout({ children }) {
return (
<html lang="en">
<body>
{children}
<ProgressBar
height="4px"
color="#fffd00"
options={{ showSpinner: false }}
shallowRouting
appDirectory
/>
</body>
</html>
);
}
Second approach wrap in a use client Providers component
'use client';
import ProgressBar from 'next-progress-bar';
const Providers = ({ children }) => {
return (
<>
{children}
<ProgressBar
height="4px"
color="#fffd00"
options={{ showSpinner: false }}
shallowRouting
appDirectory
/>
</>
);
};
export default Providers;
import Providers from './providers';
export const metadata = {
title: 'Create Next App',
description: 'Generated by create next app',
};
export default function RootLayout({ children }) {
return (
<html lang="en">
<body>
<Providers>{children}</Providers>
</body>
</html>
);
}
TypeScript
First approach in a use client layout
'use client';
import ProgressBar from 'next-progress-bar';
export default function RootLayout({
children,
}: {
children: React.ReactNode;
}) {
return (
<html lang="en">
<body>
{children}
<ProgressBar
height="4px"
color="#fffd00"
options={{ showSpinner: false }}
shallowRouting
appDirectory
/>
</body>
</html>
);
}
Second approach wrap in a use client Providers component
'use client';
import ProgressBar from 'next-progress-bar';
const Providers = ({ children }: { children: React.ReactNode }) => {
return (
<>
{children}
<ProgressBar
height="4px"
color="#fffd00"
options={{ showSpinner: false }}
shallowRouting
appDirectory
/>
</>
);
};
export default Providers;
import Providers from './providers';
export const metadata = {
title: 'Create Next App',
description: 'Generated by create next app',
};
export default function RootLayout({
children,
}: {
children: React.ReactNode;
}) {
return (
<html lang="en">
<body>
<Providers>{children}</Providers>
</body>
</html>
);
}
Props
height
Height of the progress bar - by default 2px
color
Color of the progress bar - by default #0A2FFF
options
See NProgress docs
appDirectory
If your are in the new /app directory
shallowRouting
If the progress bar is not displayed when you use shallow routing
See Next.js docs
Issues
Please file an issue for bugs, missing documentation, or unexpected behavior.
File an issue
LICENSE
MIT