Skip to content

Commit

Permalink
feat(hmr): reload if cannot update
Browse files Browse the repository at this point in the history
  • Loading branch information
posva committed Jun 21, 2024
1 parent c6fab37 commit 6044b94
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
22 changes: 22 additions & 0 deletions e2e/__snapshots__/routes.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,28 @@ exports[`e2e routes > generates the routes 1`] = `
/* no children */
}
]
export function handleHotUpdate(_router) {
if (import.meta.hot) {
import.meta.hot.data.router = _router
}
}
if (import.meta.hot) {
import.meta.hot.accept((mod) => {
const router = import.meta.hot.data.router
if (!router) {
import.meta.hot.invalidate('[unplugin-vue-router:HMR] Cannot replace the routes because there is no active router. Reloading.')
return
}
router.clearRoutes()
for (const route of mod.routes) {
router.addRoute(route)
}
router.replace('')
})
}
"
`;

Expand Down
2 changes: 1 addition & 1 deletion src/core/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ if (import.meta.hot) {
import.meta.hot.accept((mod) => {
const router = import.meta.hot.data.router
if (!router) {
console.error('❌ router not found')
import.meta.hot.invalidate('[unplugin-vue-router:HMR] Cannot replace the routes because there is no active router. Reloading.')
return
}
router.clearRoutes()
Expand Down

0 comments on commit 6044b94

Please sign in to comment.