Emite beforeleavestate event.