Skip to content

KeepAlive life cycle

Dynamic components cached by <KeepAlive> are not destroyed on switch, but switch between activation and deactivation.

ts
onActivated(() => {
  console.log("active again");
});

onDeactivated(() => {
  console.log("cached but hidden");
});

The difference between mount/unmount

SceneTrigger
First creationonMounted + onActivated
Restore from cacheonActivated
Cut away but keep cacheonDeactivated
Really remove cacheonUnmounted

Suitable for caching routing pages, tab panels, complex forms or editor instances.