From 48ecbf8a8a2a8b236acb04e1c0a1ccef0d68f6f9 Mon Sep 17 00:00:00 2001 From: maropboia <164220066+maropboia@users.noreply.github.com> Date: Fri, 3 May 2024 11:38:28 +0600 Subject: [PATCH] comment --- .vitepress/theme/composables/nprogress.ts | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/.vitepress/theme/composables/nprogress.ts b/.vitepress/theme/composables/nprogress.ts index 1ef543d46..bf110897a 100644 --- a/.vitepress/theme/composables/nprogress.ts +++ b/.vitepress/theme/composables/nprogress.ts @@ -1,23 +1,25 @@ -import nprogress, { type NProgress } from 'nprogress' -import type { EnhanceAppContext } from 'vitepress' +import nprogress, { type NProgress } from 'nprogress' // Import NProgress library and its type definition +import type { EnhanceAppContext } from 'vitepress' // Import EnhanceAppContext type definition from VitePress -export function loadProgress(router: EnhanceAppContext['router']): NProgress { - if (typeof window === 'undefined') return +export function loadProgress(router: EnhanceAppContext['router']): NProgress { // Export a function called loadProgress that takes in a router object as an argument + if (typeof window === 'undefined') return // Return early if the window object is not defined + // Initialize NProgress with some custom configurations setTimeout(() => { nprogress.configure({ showSpinner: false }) + // Set up event listeners for the router's onBeforeRouteChange and onAfterRouteChanged events const cacheBeforeRouteChange = router.onBeforeRouteChange const cacheAfterRouteChange = router.onAfterRouteChanged router.onBeforeRouteChange = (to) => { - nprogress.start() - cacheBeforeRouteChange?.(to) + nprogress.start() // Start the NProgress bar when the user navigates to a new page + cacheBeforeRouteChange?.(to) // Call the original onBeforeRouteChange event handler } router.onAfterRouteChanged = (to) => { - nprogress.done() - cacheAfterRouteChange?.(to) + nprogress.done() // Stop the NProgress bar after the route has changed + cacheAfterRouteChange?.(to) // Call the original onAfterRouteChanged event handler } }) - return nprogress + return nprogress // Return the NProgress object }