@remix-run/router 1.0.2 → 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.
package/history.ts CHANGED
@@ -125,6 +125,15 @@ export interface History {
125
125
  */
126
126
  createHref(to: To): string;
127
127
 
128
+ /**
129
+ * Encode a location the same way window.history would do (no-op for memory
130
+ * history) so we ensure our PUSH/REPLAC e navigations for data routers
131
+ * behave the same as POP
132
+ *
133
+ * @param location The incoming location from router.navigate()
134
+ */
135
+ encodeLocation(location: Location): Location;
136
+
128
137
  /**
129
138
  * Pushes a new location onto the history stack, increasing its length by one.
130
139
  * If there were any entries in the stack after the current one, they are
@@ -259,6 +268,9 @@ export function createMemoryHistory(
259
268
  createHref(to) {
260
269
  return typeof to === "string" ? to : createPath(to);
261
270
  },
271
+ encodeLocation(location) {
272
+ return location;
273
+ },
262
274
  push(to, state) {
263
275
  action = Action.Push;
264
276
  let nextLocation = createMemoryLocation(to, state);
@@ -527,6 +539,20 @@ export function parsePath(path: string): Partial<Path> {
527
539
  return parsedPath;
528
540
  }
529
541
 
542
+ export function createURL(location: Location | string): URL {
543
+ // window.location.origin is "null" (the literal string value) in Firefox
544
+ // under certain conditions, notably when serving from a local HTML file
545
+ // See https://bugzilla.mozilla.org/show_bug.cgi?id=878297
546
+ let base =
547
+ typeof window !== "undefined" &&
548
+ typeof window.location !== "undefined" &&
549
+ window.location.origin !== "null"
550
+ ? window.location.origin
551
+ : "unknown://unknown";
552
+ let href = typeof location === "string" ? location : createPath(location);
553
+ return new URL(href, base);
554
+ }
555
+
530
556
  export interface UrlHistory extends History {}
531
557
 
532
558
  export type UrlHistoryOptions = {
@@ -570,7 +596,7 @@ function getUrlBasedHistory(
570
596
  }
571
597
 
572
598
  if (v5Compat && listener) {
573
- listener({ action, location });
599
+ listener({ action, location: history.location });
574
600
  }
575
601
  }
576
602
 
@@ -584,7 +610,7 @@ function getUrlBasedHistory(
584
610
  globalHistory.replaceState(historyState, "", url);
585
611
 
586
612
  if (v5Compat && listener) {
587
- listener({ action, location: location });
613
+ listener({ action, location: history.location });
588
614
  }
589
615
  }
590
616
 
@@ -610,6 +636,16 @@ function getUrlBasedHistory(
610
636
  createHref(to) {
611
637
  return createHref(window, to);
612
638
  },
639
+ encodeLocation(location) {
640
+ // Encode a Location the same way window.location would
641
+ let url = createURL(createPath(location));
642
+ return {
643
+ ...location,
644
+ pathname: url.pathname,
645
+ search: url.search,
646
+ hash: url.hash,
647
+ };
648
+ },
613
649
  push,
614
650
  replace,
615
651
  go(n) {
package/index.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { convertRoutesToDataRoutes } from "./utils";
1
+ import { convertRoutesToDataRoutes, getPathContributingMatches } from "./utils";
2
2
 
3
3
  export type {
4
4
  ActionFunction,
@@ -79,4 +79,7 @@ export * from "./router";
79
79
  ///////////////////////////////////////////////////////////////////////////////
80
80
 
81
81
  /** @internal */
82
- export { convertRoutesToDataRoutes as UNSAFE_convertRoutesToDataRoutes };
82
+ export {
83
+ convertRoutesToDataRoutes as UNSAFE_convertRoutesToDataRoutes,
84
+ getPathContributingMatches as UNSAFE_getPathContributingMatches,
85
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@remix-run/router",
3
- "version": "1.0.2",
3
+ "version": "1.0.3-pre.1",
4
4
  "description": "Nested/Data-driven/Framework-agnostic Routing",
5
5
  "keywords": [
6
6
  "remix",
@@ -16,6 +16,7 @@
16
16
  "author": "Remix Software <hello@remix.run>",
17
17
  "sideEffects": false,
18
18
  "main": "./dist/router.cjs.js",
19
+ "unpkg": "./dist/router.umd.min.js",
19
20
  "module": "./dist/router.js",
20
21
  "types": "./dist/index.d.ts",
21
22
  "files": [