mirror of
https://github.com/fmhy/edit.git
synced 2026-02-06 03:01:08 +11:00
Show progress on route change
This commit is contained in:
parent
ea66ff6c03
commit
3c525af917
5 changed files with 130 additions and 5 deletions
23
.vitepress/theme/composables/nprogress.ts
Normal file
23
.vitepress/theme/composables/nprogress.ts
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
import nprogress, { type NProgress } from "nprogress";
|
||||
import type { EnhanceAppContext } from "vitepress";
|
||||
|
||||
export function loadProgress(router: EnhanceAppContext["router"]): NProgress {
|
||||
if (typeof window === "undefined") return;
|
||||
|
||||
setTimeout(() => {
|
||||
nprogress.configure({ showSpinner: false });
|
||||
|
||||
const cacheBeforeRouteChange = router.onBeforeRouteChange;
|
||||
const cacheAfterRouteChange = router.onAfterRouteChanged;
|
||||
router.onBeforeRouteChange = (to) => {
|
||||
nprogress.start();
|
||||
cacheBeforeRouteChange?.(to);
|
||||
};
|
||||
router.onAfterRouteChanged = (to) => {
|
||||
nprogress.done();
|
||||
cacheAfterRouteChange?.(to);
|
||||
};
|
||||
});
|
||||
|
||||
return nprogress;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue