Skip to content

Commit 6044b94

Browse files
committed
feat(hmr): reload if cannot update
1 parent c6fab37 commit 6044b94

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

e2e/__snapshots__/routes.spec.ts.snap

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,28 @@ exports[`e2e routes > generates the routes 1`] = `
118118
/* no children */
119119
}
120120
]
121+
122+
export function handleHotUpdate(_router) {
123+
if (import.meta.hot) {
124+
import.meta.hot.data.router = _router
125+
}
126+
}
127+
128+
if (import.meta.hot) {
129+
import.meta.hot.accept((mod) => {
130+
const router = import.meta.hot.data.router
131+
if (!router) {
132+
import.meta.hot.invalidate('[unplugin-vue-router:HMR] Cannot replace the routes because there is no active router. Reloading.')
133+
return
134+
}
135+
router.clearRoutes()
136+
for (const route of mod.routes) {
137+
router.addRoute(route)
138+
}
139+
router.replace('')
140+
})
141+
}
142+
121143
"
122144
`;
123145

src/core/context.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ if (import.meta.hot) {
197197
import.meta.hot.accept((mod) => {
198198
const router = import.meta.hot.data.router
199199
if (!router) {
200-
console.error('❌ router not found')
200+
import.meta.hot.invalidate('[unplugin-vue-router:HMR] Cannot replace the routes because there is no active router. Reloading.')
201201
return
202202
}
203203
router.clearRoutes()

0 commit comments

Comments
 (0)