Skip to content

Commit 9459583

Browse files
chensongnicwandev
andauthored
feat: Enable HMR for routes to avoid page reloads on changes (#124)
* feat: Enable HMR for routes * chore: Add code comment --------- Co-authored-by: Charlie ✨ <18888351756@163.com>
1 parent 15718a8 commit 9459583

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

src/router/index.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { createRouter, createWebHistory } from 'vue-router/auto'
2-
import { routes } from 'vue-router/auto-routes'
2+
import { routes, handleHotUpdate } from 'vue-router/auto-routes'
33

44
import NProgress from 'nprogress'
55
import 'nprogress/nprogress.css'
@@ -15,6 +15,11 @@ const router = createRouter({
1515
routes,
1616
})
1717

18+
// This will update routes at runtime without reloading the page
19+
if (import.meta.hot) {
20+
handleHotUpdate(router)
21+
}
22+
1823
router.beforeEach((to: EnhancedRouteLocation, from, next) => {
1924
NProgress.start()
2025

0 commit comments

Comments
 (0)