Skip to content

Commit

Permalink
feat: Enable HMR for routes to avoid page reloads on changes (#124)
Browse files Browse the repository at this point in the history
* feat: Enable HMR for routes

* chore: Add code comment

---------

Co-authored-by: Charlie ✨ <[email protected]>
  • Loading branch information
chensongni and CharleeWa authored Aug 29, 2024
1 parent 15718a8 commit 9459583
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/router/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { createRouter, createWebHistory } from 'vue-router/auto'
import { routes } from 'vue-router/auto-routes'
import { routes, handleHotUpdate } from 'vue-router/auto-routes'

import NProgress from 'nprogress'
import 'nprogress/nprogress.css'
Expand All @@ -15,6 +15,11 @@ const router = createRouter({
routes,
})

// This will update routes at runtime without reloading the page
if (import.meta.hot) {
handleHotUpdate(router)
}

router.beforeEach((to: EnhancedRouteLocation, from, next) => {
NProgress.start()

Expand Down

0 comments on commit 9459583

Please sign in to comment.