diff --git a/x-pack/package.json b/x-pack/package.json index 278f350386751..a05c64ff582f7 100644 --- a/x-pack/package.json +++ b/x-pack/package.json @@ -175,6 +175,7 @@ "handlebars": "^4.0.10", "hapi-auth-cookie": "^9.0.0", "history": "4.7.2", + "history-extra": "^4.0.2", "humps": "2.0.1", "icalendar": "0.7.1", "inline-style": "^2.0.0", @@ -268,4 +269,4 @@ "engines": { "yarn": "^1.6.0" } -} \ No newline at end of file +} diff --git a/x-pack/plugins/canvas/public/lib/history_provider.js b/x-pack/plugins/canvas/public/lib/history_provider.js index 9b7f907ceeedf..65a5acc78526d 100644 --- a/x-pack/plugins/canvas/public/lib/history_provider.js +++ b/x-pack/plugins/canvas/public/lib/history_provider.js @@ -4,11 +4,9 @@ * you may not use this file except in compliance with the Elastic License. */ -import chrome from 'ui/chrome'; import lzString from 'lz-string'; -import { createBrowserHistory, createMemoryHistory, parsePath, createPath } from 'history'; -import { get } from 'lodash'; -import { APP_ROUTE } from '../../common/lib/constants'; +import { createMemoryHistory, parsePath, createPath } from 'history'; +import createHashStateHistory from 'history-extra'; import { getWindow } from './get_window'; function wrapHistoryInstance(history) { @@ -132,17 +130,7 @@ const instances = new WeakMap(); const getHistoryInstance = win => { // if no window object, use memory module if (typeof win === 'undefined' || !win.history) return createMemoryHistory(); - - const basePath = chrome.getBasePath(); - const basename = `${basePath}${APP_ROUTE}#/`; - - // hacky fix for initial page load so basename matches with the hash - if (win.location.hash === '') win.history.replaceState({}, '', `${basename}`); - - // if window object, create browser instance - return createBrowserHistory({ - basename, - }); + return createHashStateHistory(); }; export const historyProvider = (win = getWindow()) => { @@ -150,11 +138,6 @@ export const historyProvider = (win = getWindow()) => { const instance = instances.get(win); if (instance) return instance; - // temporary fix for search params before the hash; remove them via location redirect - // they can't be preserved given this upstream issue https://github.com/ReactTraining/history/issues/564 - if (get(win, 'location.search', '').length > 0) - win.location = `${chrome.getBasePath()}${APP_ROUTE}${win.location.hash}`; - // create and cache wrapped history instance const historyInstance = getHistoryInstance(win); const wrappedInstance = wrapHistoryInstance(historyInstance); diff --git a/yarn.lock b/yarn.lock index 9c5faa5464106..2cf0eeb065f41 100644 --- a/yarn.lock +++ b/yarn.lock @@ -10595,6 +10595,11 @@ highlight.js@^9.12.0, highlight.js@~9.12.0: resolved "https://registry.yarnpkg.com/highlight.js/-/highlight.js-9.12.0.tgz#e6d9dbe57cbefe60751f02af336195870c90c01e" integrity sha1-5tnb5Xy+/mB1HwKvM2GVhwyQwB4= +history-extra@^4.0.2: + version "4.0.2" + resolved "https://registry.yarnpkg.com/history-extra/-/history-extra-4.0.2.tgz#67b512c196e0a521be1d8ac83513f00ca761d9f3" + integrity sha512-Nia8vzQHyQcxKQUt5/vxZegurkG2K23TplaWLk1V6EWTuNdZMJUJ78anwGkBcHuLBia8TFUct/R/QDlgRUA42A== + history@4.7.2, history@^4.7.2: version "4.7.2" resolved "https://registry.yarnpkg.com/history/-/history-4.7.2.tgz#22b5c7f31633c5b8021c7f4a8a954ac139ee8d5b"