惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

WordPress大学
WordPress大学
J
Java Code Geeks
Martin Fowler
Martin Fowler
Microsoft Azure Blog
Microsoft Azure Blog
月光博客
月光博客
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
人人都是产品经理
人人都是产品经理
有赞技术团队
有赞技术团队
爱范儿
爱范儿
Engineering at Meta
Engineering at Meta
GbyAI
GbyAI
博客园 - 【当耐特】
Y
Y Combinator Blog
Last Week in AI
Last Week in AI
MongoDB | Blog
MongoDB | Blog
G
Google Developers Blog
博客园 - 三生石上(FineUI控件)
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
大猫的无限游戏
大猫的无限游戏
罗磊的独立博客
The Cloudflare Blog
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
V
V2EX
博客园 - 司徒正美

Hyde Blog

Hyde Blog Hyde Blog Hyde Blog Hyde Blog Hyde Blog Hyde Blog Hyde Blog Hyde Blog Hyde Blog Hyde Blog Hyde Blog Hyde Blog Hyde Blog Hyde Blog Hyde Blog Hyde Blog Hyde Blog Hyde Blog Hyde Blog Hyde Blog Hyde Blog Hyde Blog Hyde Blog Hyde Blog Hyde Blog Hyde Blog Hyde Blog Hyde Blog Hyde Blog Hyde Blog
Hyde Blog
Hyde · 2025-10-05 · via Hyde Blog

切换路由进度条 ​

简介 ​

当你切换页面,顶部会显示进度条,使用的是 @Skyleen77/nprogress-v2

版权 ​

安装 ​

pnpmyarnnpmbun

sh

pnpm add -D nprogress-v2

sh

yarn add -D nprogress-v2

sh

npm install nprogress-v2

sh

bun add -D nprogress-v2

配置 ​

docs\.vitepress\theme\index.ts 中配置

非 SSR 环境下配置不蒜子统计配置

ts

import { NProgress } from "nprogress-v2/dist/index.js"; // 进度条组件
import "nprogress-v2/dist/index.css"; // 进度条样式

export default {
  extends: Teek, //teek主题
  async enhanceApp({ app, router }) {//添加router和async
    // 非SSR环境下配置路由进度条
    // @ts-ignore-error
    if (!import.meta.env.SSR) {
      NProgress.configure({ showSpinner: false });
      router.onBeforeRouteChange = () => NProgress.start();
      router.onAfterRouteChange = () => {
        setTimeout(() => {
          NProgress.done();
        }, 100);
      };
    }
  },
};

ts

import { inBrowser } from "vitepress"; //不蒜子统计插件
import busuanzi from "busuanzi.pure.js"; // 导入不蒜子统计插件
import "nprogress-v2/dist/index.css"; // 进度条样式 ]

export default {
  extends: Teek, //teek主题
  async enhanceApp({ app, router }) {//添加router和async
    // 不蒜子环境下配置路由进度条
    if (inBrowser) {
      NProgress.configure({ showSpinner: false });
      router.onBeforeRouteChange = () => {
        NProgress.start(); // 开始进度条
      };
      router.onAfterRouteChanged = () => {
        NProgress.done(); // 停止进度条
      };
    }
  },
};

进度条样式 ​

两种方案一种是改原始代码,另一个改自定义css样式,推荐自定义css样式

  • 路径:docs\.vitepress\theme\style\var.scss,添加以下代码

scss

/* 自定义css样式 */
// 切换路由进度条颜色样式
.nprogress .bar {
  background: linear-gradient(
    114.2deg,
    rgba(184, 215, 21, 1) -15.3%,
    rgba(148, 187, 233, 1) 14.5%,
    rgba(21, 215, 182, 1) 38.7%,
    rgba(129, 189, 240, 1) 58.8%,
    rgba(219, 108, 205, 1) 77.3%,
    rgba(240, 129, 129, 1) 88.5%
  ) !important;
}
  • 路径:node_modules\.pnpm\nprogress-v2@1.1.10\node_modules\nprogress-v2\dist\index.css

css

/* 改原始代码 */
.nprogress .bar {
  background: linear-gradient(
    114.2deg,
    rgba(184, 215, 21, 1) -15.3%,
    rgba(148, 187, 233, 1) 14.5%,
    rgba(21, 215, 182, 1) 38.7%,
    rgba(129, 189, 240, 1) 58.8%,
    rgba(219, 108, 205, 1) 77.3%,
    rgba(240, 129, 129, 1) 88.5%
  );

  position: fixed;
  z-index: 99999;
  top: 0;
  left: 0;

  width: 100%;
  height: 2px;
}

效果 ​

可以参考博主VitePress