Updating router to handle before unload event