mirror of
https://github.com/fmhy/edit.git
synced 2026-02-18 17:21:22 +11:00
comment
This commit is contained in:
parent
4281fabd71
commit
48ecbf8a8a
1 changed files with 11 additions and 9 deletions
|
|
@ -1,23 +1,25 @@
|
||||||
import nprogress, { type NProgress } from 'nprogress'
|
import nprogress, { type NProgress } from 'nprogress' // Import NProgress library and its type definition
|
||||||
import type { EnhanceAppContext } from 'vitepress'
|
import type { EnhanceAppContext } from 'vitepress' // Import EnhanceAppContext type definition from VitePress
|
||||||
|
|
||||||
export function loadProgress(router: EnhanceAppContext['router']): NProgress {
|
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
|
if (typeof window === 'undefined') return // Return early if the window object is not defined
|
||||||
|
|
||||||
|
// Initialize NProgress with some custom configurations
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
nprogress.configure({ showSpinner: false })
|
nprogress.configure({ showSpinner: false })
|
||||||
|
|
||||||
|
// Set up event listeners for the router's onBeforeRouteChange and onAfterRouteChanged events
|
||||||
const cacheBeforeRouteChange = router.onBeforeRouteChange
|
const cacheBeforeRouteChange = router.onBeforeRouteChange
|
||||||
const cacheAfterRouteChange = router.onAfterRouteChanged
|
const cacheAfterRouteChange = router.onAfterRouteChanged
|
||||||
router.onBeforeRouteChange = (to) => {
|
router.onBeforeRouteChange = (to) => {
|
||||||
nprogress.start()
|
nprogress.start() // Start the NProgress bar when the user navigates to a new page
|
||||||
cacheBeforeRouteChange?.(to)
|
cacheBeforeRouteChange?.(to) // Call the original onBeforeRouteChange event handler
|
||||||
}
|
}
|
||||||
router.onAfterRouteChanged = (to) => {
|
router.onAfterRouteChanged = (to) => {
|
||||||
nprogress.done()
|
nprogress.done() // Stop the NProgress bar after the route has changed
|
||||||
cacheAfterRouteChange?.(to)
|
cacheAfterRouteChange?.(to) // Call the original onAfterRouteChanged event handler
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
return nprogress
|
return nprogress // Return the NProgress object
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue