From ea0a1cd858ca28de707ccdae40bd84761bee089e Mon Sep 17 00:00:00 2001 From: ngxson Date: Sat, 1 Aug 2020 11:16:10 +0200 Subject: [PATCH] fix Navigation.clearHistory --- src/popup/APIService.js | 3 +-- src/popup/Navigation.js | 4 +++- src/popup/components/ApiKeySetting.vue | 3 +-- src/popup/components/AppSettings.vue | 3 +-- 4 files changed, 6 insertions(+), 7 deletions(-) diff --git a/src/popup/APIService.js b/src/popup/APIService.js index a4f0095..6a13dcd 100644 --- a/src/popup/APIService.js +++ b/src/popup/APIService.js @@ -101,8 +101,7 @@ async function handle401Error() { Utils.showError("Authentication error, please login again"); await SLStorage.remove(SLStorage.SETTINGS.API_KEY); EventManager.broadcast(EventManager.EVENT.SETTINGS_CHANGED); - Navigation.clearHistory(); - Navigation.navigateTo(Navigation.PATH.LOGIN); + Navigation.clearHistoryAndNavigateTo(Navigation.PATH.LOGIN); } function bindQueryParams(url, params) { diff --git a/src/popup/Navigation.js b/src/popup/Navigation.js index 6f63888..69e4f9c 100644 --- a/src/popup/Navigation.js +++ b/src/popup/Navigation.js @@ -68,8 +68,10 @@ class Navigation { router.go(-1); } - static clearHistory() { + static clearHistoryAndNavigateTo(path) { + router.history.stack = []; router.history.index = -1; + setTimeout(() => router.push(path), 10); } } diff --git a/src/popup/components/ApiKeySetting.vue b/src/popup/components/ApiKeySetting.vue index 5e657b2..0018428 100644 --- a/src/popup/components/ApiKeySetting.vue +++ b/src/popup/components/ApiKeySetting.vue @@ -74,8 +74,7 @@ export default { EventManager.broadcast(EventManager.EVENT.SETTINGS_CHANGED); Utils.showSuccess(`Hi ${userName}!`); - Navigation.clearHistory(); - Navigation.navigateTo(Navigation.PATH.MAIN); + Navigation.clearHistoryAndNavigateTo(Navigation.PATH.MAIN); }) .catch((err) => { Utils.showError("Incorrect API Key."); diff --git a/src/popup/components/AppSettings.vue b/src/popup/components/AppSettings.vue index 091ee08..6ff3f86 100644 --- a/src/popup/components/AppSettings.vue +++ b/src/popup/components/AppSettings.vue @@ -123,8 +123,7 @@ export default { await callAPI(API_ROUTE.LOGOUT, {}, {}, API_ON_ERR.IGNORE); await SLStorage.remove(SLStorage.SETTINGS.API_KEY); EventManager.broadcast(EventManager.EVENT.SETTINGS_CHANGED); - Navigation.clearHistory(); - Navigation.navigateTo(Navigation.PATH.LOGIN); + Navigation.clearHistoryAndNavigateTo(Navigation.PATH.LOGIN); }, async setMailToUri() {