location_util.ts 714 B

1234567891011121314151617
  1. import config from 'app/core/config';
  2. // Slash encoding for angular location provider, see https://github.com/angular/angular.js/issues/10479
  3. const SLASH = '<SLASH>';
  4. export const decodePathComponent = (pc: string) => decodeURIComponent(pc).replace(new RegExp(SLASH, 'g'), '/');
  5. export const encodePathComponent = (pc: string) => encodeURIComponent(pc.replace(/\//g, SLASH));
  6. export const stripBaseFromUrl = url => {
  7. const appSubUrl = config.appSubUrl;
  8. const stripExtraChars = appSubUrl.endsWith('/') ? 1 : 0;
  9. const urlWithoutBase =
  10. url.length > 0 && url.indexOf(appSubUrl) === 0 ? url.slice(appSubUrl.length - stripExtraChars) : url;
  11. return urlWithoutBase;
  12. };
  13. export default { stripBaseFromUrl };