Skip to content

Commit

Permalink
fix(router): invalidate ongoing navigation when unmounting
Browse files Browse the repository at this point in the history
  • Loading branch information
posva committed Aug 2, 2021
1 parent 8217de6 commit d8fb7d0
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/router.ts
Expand Up @@ -923,7 +923,7 @@ export function createRouter(options: RouterOptions): Router {
markAsReady()
}

let removeHistoryListener: () => void
let removeHistoryListener: () => void | undefined
// attach listener to history to trigger navigations
function setupListeners() {
removeHistoryListener = routerHistory.listen((to, _from, info) => {
Expand Down Expand Up @@ -1195,8 +1195,11 @@ export function createRouter(options: RouterOptions): Router {
installedApps.add(app)
app.unmount = function () {
installedApps.delete(app)
// the router is not attached to an app anymore
if (installedApps.size < 1) {
removeHistoryListener()
// invalidate the current navigation
pendingLocation = START_LOCATION_NORMALIZED
removeHistoryListener && removeHistoryListener()
currentRoute.value = START_LOCATION_NORMALIZED
started = false
ready = false
Expand Down

0 comments on commit d8fb7d0

Please sign in to comment.