This question is specific to Dojo 2 not dojo 1
onDetach is called when a widget is removed from the widget tree and therefore the DOM. onDetach is called recursively down the tree to ensure that even if a widget at the top of the tree is removed all the child widgets onDetach callbacks are fired.
class MyClass extends WidgetBase {
onDetach() {
// do things when removed from the DOM
}
}