Fix a bug that onBeforeNavigation will throw an exception.