From 219fd10eb2a9bcab6f91ba82d4f75c325f40875c Mon Sep 17 00:00:00 2001 From: Jordan Eldredge Date: Sun, 6 Sep 2020 21:46:19 -0700 Subject: [PATCH] Don't try to pollute history --- src/redux/store.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/redux/store.js b/src/redux/store.js index 881ed612..e04c0936 100644 --- a/src/redux/store.js +++ b/src/redux/store.js @@ -10,7 +10,7 @@ export function createStore() { const store = createReduxStore(reducer, applyMiddleware(epicMiddleware)); epicMiddleware.run(rootEpic); - let lastUrl = null; + let lastUrl = window.location.pathname; window.onpopstate = function () { store.dispatch({ type: "URL_CHANGED", location: document.location }); }; @@ -21,11 +21,14 @@ export function createStore() { const state = store.getState(); const url = Selectors.getUrl(state); if (url !== lastUrl) { + console.log( + `url ${url} does not match ${lastUrl} so we're adding a history entry` + ); window.ga("set", "page", url); if (lastUrl != null) { window.ga("send", "pageview"); } - window.history.pushState({}, Selectors.getPageTitle(state), url); + window.history.replaceState({}, Selectors.getPageTitle(state), url); lastUrl = url; } });