@remix-run/router 1.0.3-pre.0 → 1.0.3-pre.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @remix-run/router v1.0.3-pre.0
2
+ * @remix-run/router v1.0.3-pre.1
3
3
  *
4
4
  * Copyright (c) Remix Software Inc.
5
5
  *
@@ -115,6 +115,10 @@
115
115
  return typeof to === "string" ? to : createPath(to);
116
116
  },
117
117
 
118
+ encodeLocation(location) {
119
+ return location;
120
+ },
121
+
118
122
  push(to, state) {
119
123
  action = exports.Action.Push;
120
124
  let nextLocation = createMemoryLocation(to, state);
@@ -372,6 +376,14 @@
372
376
 
373
377
  return parsedPath;
374
378
  }
379
+ function createURL(location) {
380
+ // window.location.origin is "null" (the literal string value) in Firefox
381
+ // under certain conditions, notably when serving from a local HTML file
382
+ // See https://bugzilla.mozilla.org/show_bug.cgi?id=878297
383
+ let base = typeof window !== "undefined" && typeof window.location !== "undefined" && window.location.origin !== "null" ? window.location.origin : "unknown://unknown";
384
+ let href = typeof location === "string" ? location : createPath(location);
385
+ return new URL(href, base);
386
+ }
375
387
 
376
388
  function getUrlBasedHistory(getLocation, createHref, validateLocation, options) {
377
389
  if (options === void 0) {
@@ -462,6 +474,16 @@
462
474
  return createHref(window, to);
463
475
  },
464
476
 
477
+ encodeLocation(location) {
478
+ // Encode a Location the same way window.location would
479
+ let url = createURL(createPath(location));
480
+ return _extends({}, location, {
481
+ pathname: url.pathname,
482
+ search: url.search,
483
+ hash: url.hash
484
+ });
485
+ },
486
+
465
487
  push,
466
488
  replace,
467
489
 
@@ -550,9 +572,12 @@
550
572
  let matches = null;
551
573
 
552
574
  for (let i = 0; matches == null && i < branches.length; ++i) {
553
- matches = matchRouteBranch(branches[i], // incoming pathnames are always encoded from either window.location or
554
- // from route.navigate, but we want to match against the unencoded paths
555
- // in the route definitions
575
+ matches = matchRouteBranch(branches[i], // Incoming pathnames are generally encoded from either window.location
576
+ // or from router.navigate, but we want to match against the unencoded
577
+ // paths in the route definitions. Memory router locations won't be
578
+ // encoded here but there also shouldn't be anything to decode so this
579
+ // should be a safe operation. This avoids needing matchRoutes to be
580
+ // history-aware.
556
581
  safelyDecodeURI(pathname));
557
582
  }
558
583
 
@@ -1484,12 +1509,7 @@
1484
1509
  // the same encoding we'd get from a history.pushState/window.location read
1485
1510
  // without having to touch history
1486
1511
 
1487
- let url = createURL(createPath(location));
1488
- location = _extends({}, location, {
1489
- pathname: url.pathname,
1490
- search: url.search,
1491
- hash: url.hash
1492
- });
1512
+ location = init.history.encodeLocation(location);
1493
1513
  let historyAction = (opts && opts.replace) === true || submission != null ? exports.Action.Replace : exports.Action.Push;
1494
1514
  let preventScrollReset = opts && "preventScrollReset" in opts ? opts.preventScrollReset === true : undefined;
1495
1515
  return await startNavigation(historyAction, location, {
@@ -2562,8 +2582,6 @@
2562
2582
  let result;
2563
2583
 
2564
2584
  if (!actionMatch.route.action) {
2565
- let href = createServerHref(new URL(request.url));
2566
-
2567
2585
  if (isRouteRequest) {
2568
2586
  throw createRouterErrorResponse(null, {
2569
2587
  status: 405,
@@ -2571,7 +2589,7 @@
2571
2589
  });
2572
2590
  }
2573
2591
 
2574
- result = getMethodNotAllowedResult(href);
2592
+ result = getMethodNotAllowedResult(request.url);
2575
2593
  } else {
2576
2594
  result = await callLoaderOrAction("action", request, actionMatch, matches, undefined, // Basename not currently supported in static handlers
2577
2595
  true, isRouteRequest);
@@ -2755,7 +2773,7 @@
2755
2773
  path,
2756
2774
  submission: {
2757
2775
  formMethod: opts.formMethod,
2758
- formAction: createServerHref(parsePath(path)),
2776
+ formAction: stripHashFromPath(path),
2759
2777
  formEncType: opts && opts.formEncType || "application/x-www-form-urlencoded",
2760
2778
  formData: opts.formData
2761
2779
  }
@@ -3035,7 +3053,7 @@
3035
3053
  }
3036
3054
 
3037
3055
  function createRequest(location, signal, submission) {
3038
- let url = createURL(location).toString();
3056
+ let url = createURL(stripHashFromPath(location)).toString();
3039
3057
  let init = {
3040
3058
  signal
3041
3059
  };
@@ -3228,7 +3246,7 @@
3228
3246
  }
3229
3247
 
3230
3248
  function getMethodNotAllowedResult(path) {
3231
- let href = typeof path === "string" ? path : createServerHref(path);
3249
+ let href = typeof path === "string" ? path : createPath(path);
3232
3250
  console.warn("You're trying to submit to a route that does not have an action. To " + "fix this, please add an `action` function to the route for " + ("[" + href + "]"));
3233
3251
  return {
3234
3252
  type: ResultType.error,
@@ -3245,11 +3263,13 @@
3245
3263
  return result;
3246
3264
  }
3247
3265
  }
3248
- } // Create an href to represent a "server" URL without the hash
3249
-
3266
+ }
3250
3267
 
3251
- function createServerHref(location) {
3252
- return (location.pathname || "") + (location.search || "");
3268
+ function stripHashFromPath(path) {
3269
+ let parsedPath = typeof path === "string" ? parsePath(path) : path;
3270
+ return createPath(_extends({}, parsedPath, {
3271
+ hash: ""
3272
+ }));
3253
3273
  }
3254
3274
 
3255
3275
  function isHashChangeOnly(a, b) {
@@ -3367,12 +3387,6 @@
3367
3387
 
3368
3388
  let pathMatches = getPathContributingMatches(matches);
3369
3389
  return pathMatches[pathMatches.length - 1];
3370
- }
3371
-
3372
- function createURL(location) {
3373
- let base = typeof window !== "undefined" && typeof window.location !== "undefined" ? window.location.origin : "unknown://unknown";
3374
- let href = typeof location === "string" ? location : createServerHref(location);
3375
- return new URL(href, base);
3376
3390
  } //#endregion
3377
3391
 
3378
3392
  exports.AbortedDeferredError = AbortedDeferredError;