使用 nprogress 创建的 Next.js 顶部加载条组件,可与 Next.js 16、Next.js 15 和 React 相结合使用。
使用 nprogress 创建的 Next.js 顶部加载条组件,可与 Next.js 16、Next.js 15 和 React 相结合使用。
使用 npm:
npm install nextjs-toploader使用 yarn:
yarn add nextjs-toploader使用导入:
import NextTopLoader from 'nextjs-toploader';app/layout.js 来配置 app 文件夹结构要进行渲染,请在 RootLayout() 的 内添加 到 return():
import NextTopLoader from 'nextjs-toploader';
export default function RootLayout({ children }) {
return (
{children}
);
}pages/_app.js 来配置 pages 文件夹结构对于渲染,请在 MyApp() 中的 return() 中添加 ``(推荐):
import { PagesTopLoader } from 'nextjs-toploader/pages';
export default function MyApp({ Component, pageProps }) {
return (
<>
;
);
}您也可以在 pages 路由中使用 ``,但建议使用 useRouter 钩子支持,该支持自 nextjs-toploader 2.6.12 版本开始提供。
useRouter 钩子的兼容性useRouter 钩子与 app/layout.js 来处理 app 文件夹结构中的 TopLoader 触发(App Router):// Import the useRouter hook from nextjs-toploader to trigger the TopLoader
import { useRouter } from 'nextjs-toploader/app';| 名称 | 描述 |
|---|
暂无开放 Issues,或尚未同步最近议题。