From 3fbba4e90bb28177c4279871687fa2ad9da56558 Mon Sep 17 00:00:00 2001 From: Sam Bhagwat Date: Thu, 11 Jan 2018 15:08:39 -0800 Subject: [PATCH] correct key behavior (#3483) * correct key behavior * remove trailing slash logic * remove adding new variable --- packages/gatsby-react-router-scroll/src/StateStorage.js | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/packages/gatsby-react-router-scroll/src/StateStorage.js b/packages/gatsby-react-router-scroll/src/StateStorage.js index a34c647ad4185..56b2adff21f46 100644 --- a/packages/gatsby-react-router-scroll/src/StateStorage.js +++ b/packages/gatsby-react-router-scroll/src/StateStorage.js @@ -6,7 +6,7 @@ export default class SessionStorage { const stateKey = this.getStateKey(location, key) try { - const value = sessionStorage.getItem(stateKey) + const value = window.sessionStorage.getItem(stateKey) return JSON.parse(value) } catch (e) { console.warn( @@ -30,7 +30,7 @@ export default class SessionStorage { const storedValue = JSON.stringify(value) try { - sessionStorage.setItem(stateKey, storedValue) + window.sessionStorage.setItem(stateKey, storedValue) } catch (e) { if (window && window[GATSBY_ROUTER_SCROLL_STATE]) { window[GATSBY_ROUTER_SCROLL_STATE][stateKey] = JSON.parse(storedValue) @@ -46,8 +46,7 @@ export default class SessionStorage { } getStateKey(location, key) { - const locationKey = location.key - const stateKeyBase = `${STATE_KEY_PREFIX}${locationKey}` + const stateKeyBase = `${STATE_KEY_PREFIX}${location.pathname}` return key === null || typeof key === `undefined` ? stateKeyBase : `${stateKeyBase}|${key}`