From 4da342befddc2031e0bf91dfc5aa9f6c194644b6 Mon Sep 17 00:00:00 2001 From: Dani Palou Date: Tue, 2 Feb 2021 08:10:12 +0100 Subject: [PATCH] MOBILE-3648 navigator: Store params in localStorage in browser --- src/core/services/navigator.ts | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/core/services/navigator.ts b/src/core/services/navigator.ts index 79e32efcd..1789848fa 100644 --- a/src/core/services/navigator.ts +++ b/src/core/services/navigator.ts @@ -29,6 +29,7 @@ import { CoreTextUtils } from '@services/utils/text'; import { makeSingleton, NavController, Router } from '@singletons'; import { CoreScreen } from './screen'; import { filter } from 'rxjs/operators'; +import { CoreApp } from './app'; const DEFAULT_MAIN_MENU_TAB = CoreMainMenuHomeHandlerService.PAGE_NAME; @@ -255,10 +256,19 @@ export class CoreNavigatorService { value = params[name]; } - const storedParam = this.storedParams[value]; + let storedParam = this.storedParams[value]; + // Remove the parameter from our map if it's in there. delete this.storedParams[value]; + if (!CoreApp.instance.isMobile() && !storedParam) { + // Try to retrieve the param from local storage in browser. + const storageParam = localStorage.getItem(value); + if (storageParam) { + storedParam = CoreTextUtils.instance.parseJSON(storageParam); + } + } + return storedParam ?? value; } @@ -368,6 +378,11 @@ export class CoreNavigatorService { const id = this.getNewParamId(); this.storedParams[id] = value; queryParams[name] = id; + + if (!CoreApp.instance.isMobile()) { + // In browser, save the param in local storage to be able to retrieve it if the app is refreshed. + localStorage.setItem(id, JSON.stringify(value)); + } } }