eddev 2.0.0-beta.29 → 2.0.0-beta.30
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/dist/app/lib/routing/components/BrowserRouter.js +15 -8
- package/dist/app/lib/routing/components/Link.d.ts +1 -1
- package/dist/app/lib/routing/types.d.ts +1 -1
- package/dist/app/lib/routing/utils.d.ts +1 -0
- package/dist/app/lib/routing/utils.js +5 -0
- package/dist/node/cli/version.d.ts +1 -1
- package/dist/node/cli/version.js +1 -1
- package/package.json +1 -1
|
@@ -3,10 +3,18 @@ import { useEffect, useMemo, useRef, useState, useTransition } from "react";
|
|
|
3
3
|
import { isEqual, isRelative, parseURL, resolveURL } from "ufo";
|
|
4
4
|
import { RouterContext, RouterStateContext } from "../context.js";
|
|
5
5
|
import { RouteLoader } from "../loader.js";
|
|
6
|
-
import { getLinkHandlerMode, getRouteMeta, normalizeRoute, parseQuery, stringifyRouteLink } from "../utils.js";
|
|
6
|
+
import { getLinkHandlerMode, getRouteMeta, isSamePathname, normalizeRoute, parseQuery, stringifyRouteLink, } from "../utils.js";
|
|
7
7
|
import { AppRenderer } from "./RouteRenderer.js";
|
|
8
8
|
import { $routeMetaStore } from "../hooks/useRouteMeta.js";
|
|
9
|
+
// Create a global RouteLoader instance
|
|
9
10
|
const loader = new RouteLoader();
|
|
11
|
+
// Create a unique ID for each history entry
|
|
12
|
+
let historyStamp = String(new Date().getTime());
|
|
13
|
+
let historyIndex = 0;
|
|
14
|
+
function getHistoryId() {
|
|
15
|
+
return historyStamp + historyIndex++;
|
|
16
|
+
}
|
|
17
|
+
// Set up the initial route data
|
|
10
18
|
let initialRoute;
|
|
11
19
|
let initialRouteHydrated = false;
|
|
12
20
|
if (env.client && !env.admin) {
|
|
@@ -58,10 +66,6 @@ function historyStateForRoute(route) {
|
|
|
58
66
|
state: route.returnState,
|
|
59
67
|
};
|
|
60
68
|
}
|
|
61
|
-
let index = 0;
|
|
62
|
-
function getHistoryId() {
|
|
63
|
-
return String(index++);
|
|
64
|
-
}
|
|
65
69
|
let lastRouterState = null;
|
|
66
70
|
export function BrowserRouter(props) {
|
|
67
71
|
const pendingRoute = useRef(null);
|
|
@@ -319,9 +323,12 @@ export function BrowserRouter(props) {
|
|
|
319
323
|
e.preventDefault();
|
|
320
324
|
if (preferBack) {
|
|
321
325
|
const lastState = state.history.length > 1 && state.history[state.history.length - 2];
|
|
322
|
-
if (lastState
|
|
323
|
-
|
|
324
|
-
|
|
326
|
+
if (lastState) {
|
|
327
|
+
const doesMatch = preferBack === "exact" ? isEqual(href, lastState.uri) : isSamePathname(href, lastState.uri);
|
|
328
|
+
if (doesMatch) {
|
|
329
|
+
history.back();
|
|
330
|
+
return;
|
|
331
|
+
}
|
|
325
332
|
}
|
|
326
333
|
}
|
|
327
334
|
api.navigate(href);
|
|
@@ -3,7 +3,7 @@ type Props<T extends ElementType = "a"> = NoInfer<Omit<ComponentPropsWithRef<T>,
|
|
|
3
3
|
href?: string | null;
|
|
4
4
|
target?: string | null;
|
|
5
5
|
as?: T;
|
|
6
|
-
preferBack?: boolean;
|
|
6
|
+
preferBack?: boolean | "exact";
|
|
7
7
|
};
|
|
8
8
|
export declare const Link: <T extends ElementType = "a">(props: Props<T>) => ReactElement;
|
|
9
9
|
/**
|
|
@@ -102,7 +102,7 @@ export type RouterAPI = {
|
|
|
102
102
|
/** Replace the hash */
|
|
103
103
|
replaceHash: (hash: string) => void;
|
|
104
104
|
/** Handle link clicking events */
|
|
105
|
-
handleClickEvent(e: PointerOrMouseEvent, href?: string, preferBack?: boolean): void;
|
|
105
|
+
handleClickEvent(e: PointerOrMouseEvent, href?: string, preferBack?: boolean | "exact"): void;
|
|
106
106
|
/** A reference to the route loader (mostly for internal use) */
|
|
107
107
|
loader: RouteLoader;
|
|
108
108
|
/** Subscribe to events */
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { MouseEvent as ReactMouseEvent, PointerEvent as ReactPointerEvent } from "react";
|
|
2
2
|
import { RouteData, RouteLink, RouteMeta, RouteState } from "./types.js";
|
|
3
3
|
export declare function isSameOrigin(url: string): boolean;
|
|
4
|
+
export declare function isSamePathname(a: string, b: string): boolean;
|
|
4
5
|
export type PointerOrMouseEvent = MouseEvent | PointerEvent | ReactMouseEvent | ReactPointerEvent;
|
|
5
6
|
export type LinkHandlerMode = {
|
|
6
7
|
mode: "ignore" | "navigate" | "native";
|
|
@@ -10,6 +10,11 @@ export function isSameOrigin(url) {
|
|
|
10
10
|
return parsed.protocol === document.location.protocol && parsed.host === document.location.host;
|
|
11
11
|
}
|
|
12
12
|
}
|
|
13
|
+
export function isSamePathname(a, b) {
|
|
14
|
+
const left = parseURL(a).pathname.replace(/\/$/, "").toLocaleLowerCase();
|
|
15
|
+
const right = parseURL(b).pathname.replace(/\/$/, "").toLocaleLowerCase();
|
|
16
|
+
return left === right;
|
|
17
|
+
}
|
|
13
18
|
export function getLinkHandlerMode(e, href) {
|
|
14
19
|
try {
|
|
15
20
|
// Attempt to get the link element, if there is one
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const VERSION = "2.0.0-beta.
|
|
1
|
+
export declare const VERSION = "2.0.0-beta.30";
|
package/dist/node/cli/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const VERSION = "2.0.0-beta.
|
|
1
|
+
export const VERSION = "2.0.0-beta.30";
|