parse-relative-url.js 998 B

123456789101112131415161718192021222324
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.parseRelativeUrl = parseRelativeUrl;
  6. var _utils = require("../../utils");
  7. var _querystring = require("./querystring");
  8. function parseRelativeUrl(url, base) {
  9. const globalBase = new URL(typeof window === 'undefined' ? 'http://n' : (0, _utils).getLocationOrigin());
  10. const resolvedBase = base ? new URL(base, globalBase) : url.startsWith('.') ? new URL(typeof window === 'undefined' ? 'http://n' : window.location.href) : globalBase;
  11. const { pathname , searchParams , search , hash , href , origin } = new URL(url, resolvedBase);
  12. if (origin !== globalBase.origin) {
  13. throw new Error(`invariant: invalid relative URL, router received ${url}`);
  14. }
  15. return {
  16. pathname,
  17. query: (0, _querystring).searchParamsToUrlQuery(searchParams),
  18. search,
  19. hash,
  20. href: href.slice(globalBase.origin.length)
  21. };
  22. }
  23. //# sourceMappingURL=parse-relative-url.js.map