diff --git a/src/ui/public/chrome/api/__tests__/nav.js b/src/ui/public/chrome/api/__tests__/nav.js index 735cde468398..18de36643071 100644 --- a/src/ui/public/chrome/api/__tests__/nav.js +++ b/src/ui/public/chrome/api/__tests__/nav.js @@ -45,6 +45,19 @@ describe('chrome nav apis', function () { }); }); + describe('#removeBasePath', () => { + it ('returns the given URL as-is when no basepath is set', () => { + const basePath = ''; + const { chrome } = init({ basePath }); + expect(chrome.removeBasePath('/app/kibana?a=b')).to.be('/app/kibana?a=b'); + }); + + it ('returns the given URL with the basepath stripped out when basepath is set', () => { + const { chrome } = init(); + expect(chrome.removeBasePath(`${basePath}/app/kibana?a=b`)).to.be('/app/kibana?a=b'); + }); + }); + describe('#getNavLinkById', () => { it ('retrieves the correct nav link, given its ID', () => { const appUrlStore = new StubBrowserStorage(); diff --git a/src/ui/public/chrome/api/nav.js b/src/ui/public/chrome/api/nav.js index f78ea3a36416..66e27445c088 100644 --- a/src/ui/public/chrome/api/nav.js +++ b/src/ui/public/chrome/api/nav.js @@ -38,6 +38,15 @@ export default function (chrome, internals) { }); }; + chrome.removeBasePath = function (url) { + if (!internals.basePath) { + return url; + } + + const basePathRegExp = new RegExp(`^${internals.basePath}`); + return url.replace(basePathRegExp, ''); + }; + function lastSubUrlKey(link) { return `lastSubUrl:${link.url}`; }