Feat: Support url params (#25828)

Closes https://github.com/elastic/kibana/issues/23046

Switch to a hash history manager that supports pushState and replaceState. This makes the "basepath" part of the hash's concern, so anything before the hash no longer matters. This also allows undoing a bunch of hacky fixes.

This also allows the `urlparam` function to work again! ヽ(;▽;)ノ

![screenshot 2018-11-16 12 51 14 1](https://user-images.githubusercontent.com/404731/48645245-508a1300-e9a2-11e8-8959-1ede474b78dd.jpg)
This commit is contained in:
Joe Fleming 2018-11-19 12:41:01 -07:00 committed by joe fleming
parent 5d73ffadd5
commit 1edb9a9bc8
3 changed files with 10 additions and 21 deletions

View file

@ -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",
@ -269,4 +270,4 @@
"engines": {
"yarn": "^1.6.0"
}
}
}

View file

@ -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);

View file

@ -10582,6 +10582,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"