@real-router/react 0.27.2 → 0.27.4
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/cjs/{Link-CyDwbrFA.js → Link-D4K4T0Ef.js} +2 -2
- package/dist/cjs/{Link-CyDwbrFA.js.map → Link-D4K4T0Ef.js.map} +1 -1
- package/dist/cjs/{RouterErrorBoundary-3UhUelqY.d.ts → RouterErrorBoundary-k17kf8Rr.d.ts} +3 -3
- package/dist/cjs/{RouterErrorBoundary-3UhUelqY.d.ts.map → RouterErrorBoundary-k17kf8Rr.d.ts.map} +1 -1
- package/dist/cjs/{RouterProvider-CPsCmrRw.js → RouterProvider-CAaKExt_.js} +2 -2
- package/dist/cjs/RouterProvider-CAaKExt_.js.map +1 -0
- package/dist/cjs/{RouterProvider-lgNarto1.d.ts → RouterProvider-xbLo90sc.d.ts} +2 -2
- package/dist/cjs/{RouterProvider-lgNarto1.d.ts.map → RouterProvider-xbLo90sc.d.ts.map} +1 -1
- package/dist/cjs/index.d.ts +3 -3
- package/dist/cjs/index.js +1 -1
- package/dist/cjs/index.react-server.d.ts +1 -1
- package/dist/cjs/ink.d.ts +2 -2
- package/dist/cjs/ink.js +1 -1
- package/dist/cjs/legacy.d.ts +3 -3
- package/dist/cjs/legacy.js +1 -1
- package/dist/cjs/{useRouterTransition-D5nwRENd.d.ts → useRouterTransition-CRFKfwuP.d.ts} +2 -2
- package/dist/cjs/{useRouterTransition-D5nwRENd.d.ts.map → useRouterTransition-CRFKfwuP.d.ts.map} +1 -1
- package/dist/esm/{Link-uERoM4yk.mjs → Link-PQIMnFd0.mjs} +2 -2
- package/dist/esm/{Link-uERoM4yk.mjs.map → Link-PQIMnFd0.mjs.map} +1 -1
- package/dist/esm/{RouterErrorBoundary-3UhUelqY.d.mts → RouterErrorBoundary-k17kf8Rr.d.mts} +3 -3
- package/dist/esm/{RouterErrorBoundary-3UhUelqY.d.mts.map → RouterErrorBoundary-k17kf8Rr.d.mts.map} +1 -1
- package/dist/esm/{RouterProvider-DCchvq4n.d.mts → RouterProvider-CG1cqrjE.d.mts} +2 -2
- package/dist/esm/{RouterProvider-DCchvq4n.d.mts.map → RouterProvider-CG1cqrjE.d.mts.map} +1 -1
- package/dist/esm/{RouterProvider-DgHypQTJ.mjs → RouterProvider-DhZoi6au.mjs} +2 -2
- package/dist/esm/RouterProvider-DhZoi6au.mjs.map +1 -0
- package/dist/esm/index.d.mts +3 -3
- package/dist/esm/index.mjs +1 -1
- package/dist/esm/index.react-server.d.mts +1 -1
- package/dist/esm/ink.d.mts +2 -2
- package/dist/esm/ink.mjs +1 -1
- package/dist/esm/legacy.d.mts +3 -3
- package/dist/esm/legacy.mjs +1 -1
- package/dist/esm/{useRouterTransition-PCwA_qj1.d.mts → useRouterTransition-C5Ubt7rP.d.mts} +2 -2
- package/dist/esm/{useRouterTransition-PCwA_qj1.d.mts.map → useRouterTransition-C5Ubt7rP.d.mts.map} +1 -1
- package/package.json +6 -7
- package/dist/cjs/RouterProvider-CPsCmrRw.js.map +0 -1
- package/dist/esm/RouterProvider-DgHypQTJ.mjs.map +0 -1
- package/src/RouterProvider.tsx +0 -148
- package/src/components/Await.tsx +0 -46
- package/src/components/ClientOnly.tsx +0 -25
- package/src/components/HttpStatusCode.tsx +0 -66
- package/src/components/HttpStatusProvider.tsx +0 -26
- package/src/components/InkLink.tsx +0 -134
- package/src/components/InkRouterProvider.tsx +0 -9
- package/src/components/Link.tsx +0 -117
- package/src/components/RouterErrorBoundary.tsx +0 -69
- package/src/components/ServerOnly.tsx +0 -26
- package/src/components/Streamed.tsx +0 -30
- package/src/components/modern/RouteView/RouteView.tsx +0 -69
- package/src/components/modern/RouteView/components.tsx +0 -19
- package/src/components/modern/RouteView/helpers.tsx +0 -231
- package/src/components/modern/RouteView/index.ts +0 -8
- package/src/components/modern/RouteView/types.ts +0 -38
- package/src/constants.ts +0 -10
- package/src/context.ts +0 -14
- package/src/hooks/useDeferred.tsx +0 -34
- package/src/hooks/useIsActiveRoute.tsx +0 -47
- package/src/hooks/useNavigator.tsx +0 -15
- package/src/hooks/useRoute.tsx +0 -32
- package/src/hooks/useRouteEnter.tsx +0 -148
- package/src/hooks/useRouteExit.tsx +0 -159
- package/src/hooks/useRouteNode.tsx +0 -37
- package/src/hooks/useRouteUtils.tsx +0 -35
- package/src/hooks/useRouter.tsx +0 -15
- package/src/hooks/useRouterTransition.tsx +0 -17
- package/src/index.react-server.ts +0 -33
- package/src/index.ts +0 -61
- package/src/ink-types.ts +0 -25
- package/src/ink.ts +0 -30
- package/src/legacy.ssr.ts +0 -35
- package/src/legacy.ts +0 -35
- package/src/ssr.react-server.ts +0 -21
- package/src/ssr.ts +0 -43
- package/src/types.ts +0 -40
- package/src/utils/createHttpStatusSink.ts +0 -27
|
@@ -1,148 +0,0 @@
|
|
|
1
|
-
import { useEffect, useLayoutEffect, useRef } from "react";
|
|
2
|
-
|
|
3
|
-
import { useRoute } from "./useRoute";
|
|
4
|
-
|
|
5
|
-
import type { State } from "@real-router/core";
|
|
6
|
-
|
|
7
|
-
export interface RouteEnterContext {
|
|
8
|
-
/** The route that was just activated. */
|
|
9
|
-
route: State;
|
|
10
|
-
/** The route that was active immediately before this navigation. */
|
|
11
|
-
previousRoute: State;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
export type RouteEnterHandler = (context: RouteEnterContext) => void;
|
|
15
|
-
|
|
16
|
-
export interface UseRouteEnterOptions {
|
|
17
|
-
/**
|
|
18
|
-
* Skip the handler when `route.name === previousRoute.name`
|
|
19
|
-
* (sort/filter/query-only navigations on the same route). Default:
|
|
20
|
-
* `true`. Symmetric with `useRouteExit`'s same-name option.
|
|
21
|
-
*/
|
|
22
|
-
skipSameRoute?: boolean;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
/**
|
|
26
|
-
* Fire `handler` once when the component mounts as a result of a
|
|
27
|
-
* navigation. Mirror of `useRouteExit` for the entry side.
|
|
28
|
-
*
|
|
29
|
-
* What this hook covers that ad-hoc `useEffect` + `useRoute()` doesn't:
|
|
30
|
-
*
|
|
31
|
-
* - **Skip-initial**: handler is skipped when there is no
|
|
32
|
-
* `previousRoute` (i.e. first-load mount). Most consumers want to
|
|
33
|
-
* fire side effects only on real navigations, not on hydration.
|
|
34
|
-
* - **Same-route skip** (default): handler is skipped when
|
|
35
|
-
* `route.name === previousRoute.name`. Sort/filter/query-only
|
|
36
|
-
* navigations re-run the effect (because `route` reference changes
|
|
37
|
-
* in `useRoute`'s snapshot), but they are not "entries" in the
|
|
38
|
-
* animation / analytics sense — the component instance has stayed
|
|
39
|
-
* mounted throughout. Opt out with `skipSameRoute: false` when
|
|
40
|
-
* the handler legitimately needs to fire on every navigation
|
|
41
|
-
* (e.g. analytics tracking each query-param flip).
|
|
42
|
-
* - **StrictMode double-mount immunity**: in dev, React's StrictMode
|
|
43
|
-
* runs every effect twice to surface bugs. Without a guard,
|
|
44
|
-
* analytics fire twice, animations restart, focus jumps. The hook
|
|
45
|
-
* tracks the last-handled `route` reference and short-circuits the
|
|
46
|
-
* second pass.
|
|
47
|
-
* - **Latest-handler ref**: the handler can change identity on every
|
|
48
|
-
* render without re-running the effect — the registered wrapper
|
|
49
|
-
* dispatches to whatever `handlerRef.current` points to.
|
|
50
|
-
* - **Mount-time `route` / `previousRoute` snapshot**: the handler
|
|
51
|
-
* receives the values that were live at the moment of mount, not
|
|
52
|
-
* the latest ones (which may have moved on if the user navigated
|
|
53
|
-
* again before the effect drained).
|
|
54
|
-
*
|
|
55
|
-
* Race-safety: `useRoute()` is wired through `useSyncExternalStore` from
|
|
56
|
-
* `@real-router/sources`, so by the time the new component's effect
|
|
57
|
-
* runs, the snapshot is the post-commit one. This is the reason we can
|
|
58
|
-
* read mount-time context from `useRoute()` instead of subscribing to
|
|
59
|
-
* `router.subscribe` directly (which fires before React schedules a
|
|
60
|
-
* re-render — the well-known race in distributed components).
|
|
61
|
-
*
|
|
62
|
-
* @example Direction-aware entry animation
|
|
63
|
-
* ```tsx
|
|
64
|
-
* useRouteEnter(({ route }) => {
|
|
65
|
-
* const direction = route.context.browser?.direction;
|
|
66
|
-
* ref.current?.classList.add(
|
|
67
|
-
* direction === "back" ? "slide-from-left" : "slide-from-right",
|
|
68
|
-
* );
|
|
69
|
-
* });
|
|
70
|
-
* ```
|
|
71
|
-
*
|
|
72
|
-
* @example Source-aware focus management
|
|
73
|
-
* ```tsx
|
|
74
|
-
* useRouteEnter(({ route }) => {
|
|
75
|
-
* if (route.context.browser?.source === "navigate") {
|
|
76
|
-
* headingRef.current?.focus();
|
|
77
|
-
* }
|
|
78
|
-
* });
|
|
79
|
-
* ```
|
|
80
|
-
*
|
|
81
|
-
* @example Analytics page-enter event (skip-initial built-in)
|
|
82
|
-
* ```tsx
|
|
83
|
-
* useRouteEnter(({ route, previousRoute }) => {
|
|
84
|
-
* analytics.track("page_enter", {
|
|
85
|
-
* route: route.name,
|
|
86
|
-
* from: previousRoute.name,
|
|
87
|
-
* });
|
|
88
|
-
* });
|
|
89
|
-
* ```
|
|
90
|
-
*
|
|
91
|
-
* @example Reading rich transition metadata via `route.transition`
|
|
92
|
-
* ```tsx
|
|
93
|
-
* useRouteEnter(({ route }) => {
|
|
94
|
-
* // route.transition: TransitionMeta — populated by core for every state
|
|
95
|
-
* if (route.transition.redirected) {
|
|
96
|
-
* showToast(`Redirected from ${route.transition.from}`);
|
|
97
|
-
* }
|
|
98
|
-
* if (route.transition.segments.activated.includes("products")) {
|
|
99
|
-
* // products subtree just became active (could be products or
|
|
100
|
-
* // products.detail). Useful for subtree-scoped side effects.
|
|
101
|
-
* }
|
|
102
|
-
* });
|
|
103
|
-
* ```
|
|
104
|
-
*/
|
|
105
|
-
export function useRouteEnter(
|
|
106
|
-
handler: RouteEnterHandler,
|
|
107
|
-
options?: UseRouteEnterOptions,
|
|
108
|
-
): void {
|
|
109
|
-
const { route, previousRoute } = useRoute();
|
|
110
|
-
const handlerRef = useRef(handler);
|
|
111
|
-
const lastHandledRouteRef = useRef<State | null>(null);
|
|
112
|
-
const skipSameRoute = options?.skipSameRoute ?? true;
|
|
113
|
-
|
|
114
|
-
// Keep the latest handler reference accessible without re-running
|
|
115
|
-
// the effect. useLayoutEffect (synchronous, post-render, pre-paint)
|
|
116
|
-
// updates the ref before the effect can read it.
|
|
117
|
-
useLayoutEffect(() => {
|
|
118
|
-
handlerRef.current = handler;
|
|
119
|
-
});
|
|
120
|
-
|
|
121
|
-
useEffect(() => {
|
|
122
|
-
// Early-exit guards, top-down:
|
|
123
|
-
//
|
|
124
|
-
// - **Skip-initial**: `state.transition.from` is undefined only
|
|
125
|
-
// for the very first state committed by `router.start()`.
|
|
126
|
-
// - **Skip-same-route**: query-only navigations have
|
|
127
|
-
// `transition.from === route.name`. Opt-out via
|
|
128
|
-
// `skipSameRoute: false`.
|
|
129
|
-
// - **StrictMode dedupe**: same `route` ref between effect
|
|
130
|
-
// cleanup + re-run in dev's strict pass. Not testable from
|
|
131
|
-
// vitest (`NODE_ENV === "test"` disables React's strict-mode
|
|
132
|
-
// double-run), so v8-ignored.
|
|
133
|
-
if (!route.transition.from) {
|
|
134
|
-
return;
|
|
135
|
-
}
|
|
136
|
-
if (skipSameRoute && route.transition.from === route.name) {
|
|
137
|
-
return;
|
|
138
|
-
}
|
|
139
|
-
/* v8 ignore start */
|
|
140
|
-
if (lastHandledRouteRef.current === route || !previousRoute) {
|
|
141
|
-
return;
|
|
142
|
-
}
|
|
143
|
-
/* v8 ignore stop */
|
|
144
|
-
|
|
145
|
-
lastHandledRouteRef.current = route;
|
|
146
|
-
handlerRef.current({ route, previousRoute });
|
|
147
|
-
}, [route, previousRoute, skipSameRoute]);
|
|
148
|
-
}
|
|
@@ -1,159 +0,0 @@
|
|
|
1
|
-
import { useEffect, useLayoutEffect, useRef } from "react";
|
|
2
|
-
|
|
3
|
-
import { useRouter } from "./useRouter";
|
|
4
|
-
|
|
5
|
-
import type { State } from "@real-router/core";
|
|
6
|
-
|
|
7
|
-
export interface RouteExitContext {
|
|
8
|
-
/** The route being left. */
|
|
9
|
-
route: State;
|
|
10
|
-
/** The route being navigated to. */
|
|
11
|
-
nextRoute: State;
|
|
12
|
-
/**
|
|
13
|
-
* AbortSignal that fires when this navigation is superseded by a later
|
|
14
|
-
* one (rapid clicks). Already filtered: when the handler runs,
|
|
15
|
-
* `signal.aborted` is guaranteed to be `false`. Use
|
|
16
|
-
* `signal.addEventListener("abort", cleanup, { once: true })` for
|
|
17
|
-
* cleanup that must run on cancellation.
|
|
18
|
-
*/
|
|
19
|
-
signal: AbortSignal;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
export interface UseRouteExitOptions {
|
|
23
|
-
/**
|
|
24
|
-
* Skip the handler when `route.name === nextRoute.name`
|
|
25
|
-
* (sort/filter/query-only navigations on the same route). Default:
|
|
26
|
-
* `true`.
|
|
27
|
-
*/
|
|
28
|
-
skipSameRoute?: boolean;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
export type RouteExitHandler = (
|
|
32
|
-
context: RouteExitContext,
|
|
33
|
-
) => void | Promise<void>;
|
|
34
|
-
|
|
35
|
-
/**
|
|
36
|
-
* Subscribe to the router's leave-window with the universal guards baked
|
|
37
|
-
* in. Wraps `router.subscribeLeave` so consumers don't repeat the same
|
|
38
|
-
* boilerplate every time:
|
|
39
|
-
*
|
|
40
|
-
* - **Reentrant abort pre-check**: if `signal.aborted` is already `true`
|
|
41
|
-
* when the handler would run (rapid navigation superseded a slower
|
|
42
|
-
* one), the handler is skipped entirely. `signal.addEventListener(
|
|
43
|
-
* "abort", ...)` does not fire retroactively, so without this guard
|
|
44
|
-
* downstream cleanup would never trigger.
|
|
45
|
-
* - **Same-route skip**: by default, `route.name === nextRoute.name`
|
|
46
|
-
* short-circuits the handler — query-only navigations (sort, filter,
|
|
47
|
-
* pagination) skip the work. Opt out with `skipSameRoute: false`.
|
|
48
|
-
* - **Stable handler reference**: the handler can change identity on
|
|
49
|
-
* every render without causing resubscription — internal ref keeps
|
|
50
|
-
* the latest handler accessible to the long-lived subscription.
|
|
51
|
-
*
|
|
52
|
-
* Returns nothing — the subscription's lifecycle is bound to the
|
|
53
|
-
* component's mount.
|
|
54
|
-
*
|
|
55
|
-
* If the handler returns a Promise, the router blocks on it. If the
|
|
56
|
-
* Promise resolves, navigation proceeds. If it rejects, the router emits
|
|
57
|
-
* `TRANSITION_CANCELLED` (existing core behavior, no change here).
|
|
58
|
-
*
|
|
59
|
-
* @example Animation
|
|
60
|
-
* ```tsx
|
|
61
|
-
* const ref = useRef<HTMLDivElement>(null);
|
|
62
|
-
*
|
|
63
|
-
* useRouteExit(async ({ signal }) => {
|
|
64
|
-
* const el = ref.current;
|
|
65
|
-
* if (!el) return;
|
|
66
|
-
* el.classList.add("fade-out");
|
|
67
|
-
* const cleanup = () => el.classList.remove("fade-out");
|
|
68
|
-
* signal.addEventListener("abort", cleanup, { once: true });
|
|
69
|
-
* try {
|
|
70
|
-
* el.getBoundingClientRect(); // style flush
|
|
71
|
-
* await Promise.allSettled(el.getAnimations().map((a) => a.finished));
|
|
72
|
-
* } finally {
|
|
73
|
-
* cleanup();
|
|
74
|
-
* }
|
|
75
|
-
* });
|
|
76
|
-
* ```
|
|
77
|
-
*
|
|
78
|
-
* @example Auto-save form draft
|
|
79
|
-
* ```tsx
|
|
80
|
-
* useRouteExit(async ({ signal }) => {
|
|
81
|
-
* if (formState.dirty) await api.saveDraft(formState, { signal });
|
|
82
|
-
* });
|
|
83
|
-
* ```
|
|
84
|
-
*
|
|
85
|
-
* @example Cancel inflight requests
|
|
86
|
-
* ```tsx
|
|
87
|
-
* useRouteExit(() => {
|
|
88
|
-
* inflightController.abort();
|
|
89
|
-
* });
|
|
90
|
-
* ```
|
|
91
|
-
*
|
|
92
|
-
* @example Library-coordinated exit (motion / framer-motion)
|
|
93
|
-
* ```tsx
|
|
94
|
-
* const exitResolverRef = useRef<(() => void) | null>(null);
|
|
95
|
-
*
|
|
96
|
-
* useRouteExit(({ signal }) => {
|
|
97
|
-
* return new Promise<void>((resolve) => {
|
|
98
|
-
* exitResolverRef.current = resolve;
|
|
99
|
-
* signal.addEventListener("abort", () => resolve(), { once: true });
|
|
100
|
-
* });
|
|
101
|
-
* });
|
|
102
|
-
*
|
|
103
|
-
* const onExitComplete = () => exitResolverRef.current?.();
|
|
104
|
-
* // pass onExitComplete to <AnimatePresence>
|
|
105
|
-
* ```
|
|
106
|
-
*
|
|
107
|
-
* @example Reading rich transition metadata via `nextRoute.transition`
|
|
108
|
-
* ```tsx
|
|
109
|
-
* useRouteExit(({ route, nextRoute }) => {
|
|
110
|
-
* // nextRoute.transition: TransitionMeta — preview of the upcoming nav
|
|
111
|
-
* if (nextRoute.transition.segments.deactivated.includes("products")) {
|
|
112
|
-
* // leaving the products subtree entirely — flush product-related caches
|
|
113
|
-
* productCache.clear();
|
|
114
|
-
* }
|
|
115
|
-
* if (nextRoute.transition.redirected) {
|
|
116
|
-
* // skip animation when navigation arrived via redirect
|
|
117
|
-
* return;
|
|
118
|
-
* }
|
|
119
|
-
* });
|
|
120
|
-
* ```
|
|
121
|
-
*/
|
|
122
|
-
export function useRouteExit(
|
|
123
|
-
handler: RouteExitHandler,
|
|
124
|
-
options?: UseRouteExitOptions,
|
|
125
|
-
): void {
|
|
126
|
-
const router = useRouter();
|
|
127
|
-
const handlerRef = useRef(handler);
|
|
128
|
-
const skipSameRoute = options?.skipSameRoute ?? true;
|
|
129
|
-
|
|
130
|
-
// Keep the latest handler accessible to the subscription without
|
|
131
|
-
// resubscribing on every render — the subscription registers the
|
|
132
|
-
// wrapper once and dispatches to whatever ref points to.
|
|
133
|
-
// useLayoutEffect (synchronous, post-render, pre-paint) updates the
|
|
134
|
-
// ref before the browser can dispatch any router events that could
|
|
135
|
-
// observe a stale closure.
|
|
136
|
-
useLayoutEffect(() => {
|
|
137
|
-
handlerRef.current = handler;
|
|
138
|
-
});
|
|
139
|
-
|
|
140
|
-
useEffect(() => {
|
|
141
|
-
return router.subscribeLeave(({ route, nextRoute, signal }) => {
|
|
142
|
-
if (skipSameRoute && route.name === nextRoute.name) {
|
|
143
|
-
return;
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
// Reentrant abort: signal is already aborted when listener fires
|
|
147
|
-
// (e.g. a newer navigate superseded this one before subscribeLeave
|
|
148
|
-
// even ran). addEventListener("abort", ...) does not fire
|
|
149
|
-
// retroactively, so we skip the handler entirely — any cleanup the
|
|
150
|
-
// handler would have wired via abort listener must not run because
|
|
151
|
-
// the corresponding `add` work never happened.
|
|
152
|
-
if (signal.aborted) {
|
|
153
|
-
return;
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
return handlerRef.current({ route, nextRoute, signal });
|
|
157
|
-
});
|
|
158
|
-
}, [router, skipSameRoute]);
|
|
159
|
-
}
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import { getNavigator } from "@real-router/core";
|
|
2
|
-
import { createRouteNodeSource } from "@real-router/sources";
|
|
3
|
-
import { useMemo, useSyncExternalStore } from "react";
|
|
4
|
-
|
|
5
|
-
import { useRouter } from "./useRouter";
|
|
6
|
-
|
|
7
|
-
import type { RouteContext } from "../types";
|
|
8
|
-
|
|
9
|
-
export function useRouteNode(nodeName: string): RouteContext {
|
|
10
|
-
const router = useRouter();
|
|
11
|
-
|
|
12
|
-
const store = useMemo(
|
|
13
|
-
() => createRouteNodeSource(router, nodeName),
|
|
14
|
-
[router, nodeName],
|
|
15
|
-
);
|
|
16
|
-
|
|
17
|
-
// Use snapshot reference directly. createRouteNodeSource via stabilizeState
|
|
18
|
-
// returns the SAME snapshot when the node-relevant state did not change,
|
|
19
|
-
// so memoization on `[navigator, snapshot]` preserves identity for consumers.
|
|
20
|
-
const snapshot = useSyncExternalStore(
|
|
21
|
-
store.subscribe,
|
|
22
|
-
store.getSnapshot,
|
|
23
|
-
store.getSnapshot, // SSR: router returns same state on server and client
|
|
24
|
-
);
|
|
25
|
-
|
|
26
|
-
// getNavigator is WeakMap-cached in core; additional useMemo is redundant.
|
|
27
|
-
const navigator = getNavigator(router);
|
|
28
|
-
|
|
29
|
-
return useMemo(
|
|
30
|
-
(): RouteContext => ({
|
|
31
|
-
navigator,
|
|
32
|
-
route: snapshot.route,
|
|
33
|
-
previousRoute: snapshot.previousRoute,
|
|
34
|
-
}),
|
|
35
|
-
[navigator, snapshot],
|
|
36
|
-
);
|
|
37
|
-
}
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import { getPluginApi } from "@real-router/core/api";
|
|
2
|
-
import { getRouteUtils } from "@real-router/route-utils";
|
|
3
|
-
|
|
4
|
-
import { useRouter } from "./useRouter";
|
|
5
|
-
|
|
6
|
-
import type { RouteUtils } from "@real-router/route-utils";
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* Returns a pre-computed {@link RouteUtils} instance for the current router.
|
|
10
|
-
*
|
|
11
|
-
* `getRouteUtils` is WeakMap-cached per `RouteTreeNode` inside
|
|
12
|
-
* `@real-router/route-utils`, so the same router always returns the same
|
|
13
|
-
* `RouteUtils` instance across renders — no local cache needed in the adapter.
|
|
14
|
-
*
|
|
15
|
-
* @returns RouteUtils instance with pre-computed chains and siblings
|
|
16
|
-
*
|
|
17
|
-
* @example
|
|
18
|
-
* ```tsx
|
|
19
|
-
* const utils = useRouteUtils();
|
|
20
|
-
*
|
|
21
|
-
* utils.getChain("users.profile");
|
|
22
|
-
* // → ["users", "users.profile"]
|
|
23
|
-
*
|
|
24
|
-
* utils.getSiblings("users");
|
|
25
|
-
* // → ["admin"]
|
|
26
|
-
*
|
|
27
|
-
* utils.isDescendantOf("users.profile", "users");
|
|
28
|
-
* // → true
|
|
29
|
-
* ```
|
|
30
|
-
*/
|
|
31
|
-
export const useRouteUtils = (): RouteUtils => {
|
|
32
|
-
const router = useRouter();
|
|
33
|
-
|
|
34
|
-
return getRouteUtils(getPluginApi(router).getTree());
|
|
35
|
-
};
|
package/src/hooks/useRouter.tsx
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { useContext } from "react";
|
|
2
|
-
|
|
3
|
-
import { RouterContext } from "../context";
|
|
4
|
-
|
|
5
|
-
import type { Router } from "@real-router/core";
|
|
6
|
-
|
|
7
|
-
export const useRouter = (): Router => {
|
|
8
|
-
const router = useContext(RouterContext);
|
|
9
|
-
|
|
10
|
-
if (!router) {
|
|
11
|
-
throw new Error("useRouter must be used within a RouterProvider");
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
return router;
|
|
15
|
-
};
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { getTransitionSource } from "@real-router/sources";
|
|
2
|
-
import { useSyncExternalStore } from "react";
|
|
3
|
-
|
|
4
|
-
import { useRouter } from "./useRouter";
|
|
5
|
-
|
|
6
|
-
import type { RouterTransitionSnapshot } from "@real-router/sources";
|
|
7
|
-
|
|
8
|
-
export function useRouterTransition(): RouterTransitionSnapshot {
|
|
9
|
-
const router = useRouter();
|
|
10
|
-
const store = getTransitionSource(router);
|
|
11
|
-
|
|
12
|
-
return useSyncExternalStore(
|
|
13
|
-
store.subscribe,
|
|
14
|
-
store.getSnapshot,
|
|
15
|
-
store.getSnapshot,
|
|
16
|
-
);
|
|
17
|
-
}
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
// React Server entry — type-only re-exports under `react-server` condition (RSC bundlers). See CLAUDE.md.
|
|
2
|
-
//
|
|
3
|
-
// SSR-feature prop types (`AwaitProps`, `StreamedProps`, `ClientOnlyProps`,
|
|
4
|
-
// `ServerOnlyProps`) live in the `/ssr.react-server` entry — Server
|
|
5
|
-
// Components that need them import from `@real-router/react/ssr` (resolves
|
|
6
|
-
// to types only under the `react-server` condition).
|
|
7
|
-
|
|
8
|
-
export type { LinkProps } from "./types";
|
|
9
|
-
|
|
10
|
-
export type {
|
|
11
|
-
RouteExitContext,
|
|
12
|
-
RouteExitHandler,
|
|
13
|
-
UseRouteExitOptions,
|
|
14
|
-
} from "./hooks/useRouteExit";
|
|
15
|
-
|
|
16
|
-
export type {
|
|
17
|
-
RouteEnterContext,
|
|
18
|
-
RouteEnterHandler,
|
|
19
|
-
UseRouteEnterOptions,
|
|
20
|
-
} from "./hooks/useRouteEnter";
|
|
21
|
-
|
|
22
|
-
export type {
|
|
23
|
-
RouteViewProps,
|
|
24
|
-
RouteViewMatchProps,
|
|
25
|
-
RouteViewSelfProps,
|
|
26
|
-
RouteViewNotFoundProps,
|
|
27
|
-
} from "./components/modern/RouteView";
|
|
28
|
-
|
|
29
|
-
export type { RouterErrorBoundaryProps } from "./components/RouterErrorBoundary";
|
|
30
|
-
|
|
31
|
-
export type { Navigator } from "@real-router/core";
|
|
32
|
-
|
|
33
|
-
export type { RouterTransitionSnapshot } from "@real-router/sources";
|
package/src/index.ts
DELETED
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
// Main entry point — React 19.2+
|
|
2
|
-
//
|
|
3
|
-
// Client-side hooks + components. SSR-aware components and hooks
|
|
4
|
-
// (`<ClientOnly>`, `<ServerOnly>`, `<Await>`, `<Streamed>`, `useDeferred`)
|
|
5
|
-
// have moved to the `/ssr` subpath — import them from
|
|
6
|
-
// `@real-router/react/ssr` to opt into the SSR-feature surface.
|
|
7
|
-
|
|
8
|
-
// Components
|
|
9
|
-
export { RouteView } from "./components/modern/RouteView";
|
|
10
|
-
|
|
11
|
-
export { Link } from "./components/Link";
|
|
12
|
-
|
|
13
|
-
export { RouterErrorBoundary } from "./components/RouterErrorBoundary";
|
|
14
|
-
|
|
15
|
-
// Hooks
|
|
16
|
-
export { useRouter } from "./hooks/useRouter";
|
|
17
|
-
|
|
18
|
-
export { useNavigator } from "./hooks/useNavigator";
|
|
19
|
-
|
|
20
|
-
export { useRouteUtils } from "./hooks/useRouteUtils";
|
|
21
|
-
|
|
22
|
-
export { useRoute } from "./hooks/useRoute";
|
|
23
|
-
|
|
24
|
-
export { useRouteNode } from "./hooks/useRouteNode";
|
|
25
|
-
|
|
26
|
-
export { useRouterTransition } from "./hooks/useRouterTransition";
|
|
27
|
-
|
|
28
|
-
export { useRouteExit } from "./hooks/useRouteExit";
|
|
29
|
-
|
|
30
|
-
export { useRouteEnter } from "./hooks/useRouteEnter";
|
|
31
|
-
|
|
32
|
-
// Context
|
|
33
|
-
export { RouterProvider } from "./RouterProvider";
|
|
34
|
-
|
|
35
|
-
// Types
|
|
36
|
-
export type { LinkProps } from "./types";
|
|
37
|
-
|
|
38
|
-
export type {
|
|
39
|
-
RouteExitContext,
|
|
40
|
-
RouteExitHandler,
|
|
41
|
-
UseRouteExitOptions,
|
|
42
|
-
} from "./hooks/useRouteExit";
|
|
43
|
-
|
|
44
|
-
export type {
|
|
45
|
-
RouteEnterContext,
|
|
46
|
-
RouteEnterHandler,
|
|
47
|
-
UseRouteEnterOptions,
|
|
48
|
-
} from "./hooks/useRouteEnter";
|
|
49
|
-
|
|
50
|
-
export type {
|
|
51
|
-
RouteViewProps,
|
|
52
|
-
RouteViewMatchProps,
|
|
53
|
-
RouteViewSelfProps,
|
|
54
|
-
RouteViewNotFoundProps,
|
|
55
|
-
} from "./components/modern/RouteView";
|
|
56
|
-
|
|
57
|
-
export type { RouterErrorBoundaryProps } from "./components/RouterErrorBoundary";
|
|
58
|
-
|
|
59
|
-
export type { Navigator } from "@real-router/core";
|
|
60
|
-
|
|
61
|
-
export type { RouterTransitionSnapshot } from "@real-router/sources";
|
package/src/ink-types.ts
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import type { NavigationOptions, Params, Router } from "@real-router/core";
|
|
2
|
-
import type { ReactNode } from "react";
|
|
3
|
-
|
|
4
|
-
export interface InkLinkProps<P extends Params = Params> {
|
|
5
|
-
routeName: string;
|
|
6
|
-
routeParams?: P;
|
|
7
|
-
routeOptions?: NavigationOptions;
|
|
8
|
-
activeStrict?: boolean;
|
|
9
|
-
ignoreQueryParams?: boolean;
|
|
10
|
-
children?: ReactNode;
|
|
11
|
-
color?: string;
|
|
12
|
-
activeColor?: string;
|
|
13
|
-
focusColor?: string;
|
|
14
|
-
inverse?: boolean;
|
|
15
|
-
activeInverse?: boolean;
|
|
16
|
-
focusInverse?: boolean;
|
|
17
|
-
id?: string;
|
|
18
|
-
autoFocus?: boolean;
|
|
19
|
-
onSelect?: () => void;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
export interface InkRouterProviderProps {
|
|
23
|
-
router: Router;
|
|
24
|
-
children?: ReactNode;
|
|
25
|
-
}
|
package/src/ink.ts
DELETED
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
// Ink entry point — React 19.2+ & Ink 7+
|
|
2
|
-
|
|
3
|
-
// Components
|
|
4
|
-
export { InkLink } from "./components/InkLink";
|
|
5
|
-
|
|
6
|
-
export { InkRouterProvider } from "./components/InkRouterProvider";
|
|
7
|
-
|
|
8
|
-
export { RouterErrorBoundary } from "./components/RouterErrorBoundary";
|
|
9
|
-
|
|
10
|
-
// Hooks
|
|
11
|
-
export { useRouteNode } from "./hooks/useRouteNode";
|
|
12
|
-
|
|
13
|
-
export { useRoute } from "./hooks/useRoute";
|
|
14
|
-
|
|
15
|
-
export { useNavigator } from "./hooks/useNavigator";
|
|
16
|
-
|
|
17
|
-
export { useRouter } from "./hooks/useRouter";
|
|
18
|
-
|
|
19
|
-
export { useRouteUtils } from "./hooks/useRouteUtils";
|
|
20
|
-
|
|
21
|
-
export { useRouterTransition } from "./hooks/useRouterTransition";
|
|
22
|
-
|
|
23
|
-
// Types
|
|
24
|
-
export type { InkLinkProps, InkRouterProviderProps } from "./ink-types";
|
|
25
|
-
|
|
26
|
-
export type { RouterErrorBoundaryProps } from "./components/RouterErrorBoundary";
|
|
27
|
-
|
|
28
|
-
export type { Navigator } from "@real-router/core";
|
|
29
|
-
|
|
30
|
-
export type { RouterTransitionSnapshot } from "@real-router/sources";
|
package/src/legacy.ssr.ts
DELETED
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
// SSR-feature entry for the legacy (React 18+) entry point.
|
|
2
|
-
//
|
|
3
|
-
// `<Await>` is excluded — it depends on React 19's `use(promise)` which is
|
|
4
|
-
// not available in React 18. React 18 consumers can compose the same
|
|
5
|
-
// pattern manually with `<Suspense>` + a Suspense-aware data library.
|
|
6
|
-
|
|
7
|
-
// Components
|
|
8
|
-
export { ClientOnly } from "./components/ClientOnly";
|
|
9
|
-
|
|
10
|
-
export { ServerOnly } from "./components/ServerOnly";
|
|
11
|
-
|
|
12
|
-
export { Streamed } from "./components/Streamed";
|
|
13
|
-
|
|
14
|
-
export { HttpStatusCode } from "./components/HttpStatusCode";
|
|
15
|
-
|
|
16
|
-
export { HttpStatusProvider } from "./components/HttpStatusProvider";
|
|
17
|
-
|
|
18
|
-
// Hooks
|
|
19
|
-
export { useDeferred } from "./hooks/useDeferred";
|
|
20
|
-
|
|
21
|
-
// Utilities
|
|
22
|
-
export { createHttpStatusSink } from "./utils/createHttpStatusSink";
|
|
23
|
-
|
|
24
|
-
// Types
|
|
25
|
-
export type { ClientOnlyProps } from "./components/ClientOnly";
|
|
26
|
-
|
|
27
|
-
export type { ServerOnlyProps } from "./components/ServerOnly";
|
|
28
|
-
|
|
29
|
-
export type { StreamedProps } from "./components/Streamed";
|
|
30
|
-
|
|
31
|
-
export type { HttpStatusCodeProps } from "./components/HttpStatusCode";
|
|
32
|
-
|
|
33
|
-
export type { HttpStatusProviderProps } from "./components/HttpStatusProvider";
|
|
34
|
-
|
|
35
|
-
export type { HttpStatusSink } from "./utils/createHttpStatusSink";
|
package/src/legacy.ts
DELETED
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
// Legacy entry point — React 18+
|
|
2
|
-
//
|
|
3
|
-
// SSR-aware components/hooks live at `@real-router/react/legacy/ssr`
|
|
4
|
-
// (subset of the React 19+ `/ssr` surface — `<Await>` is excluded since
|
|
5
|
-
// it depends on `use(promise)`).
|
|
6
|
-
|
|
7
|
-
// Components
|
|
8
|
-
export { Link } from "./components/Link";
|
|
9
|
-
|
|
10
|
-
export { RouterErrorBoundary } from "./components/RouterErrorBoundary";
|
|
11
|
-
|
|
12
|
-
// Hooks
|
|
13
|
-
export { useRouteNode } from "./hooks/useRouteNode";
|
|
14
|
-
|
|
15
|
-
export { useRoute } from "./hooks/useRoute";
|
|
16
|
-
|
|
17
|
-
export { useNavigator } from "./hooks/useNavigator";
|
|
18
|
-
|
|
19
|
-
export { useRouter } from "./hooks/useRouter";
|
|
20
|
-
|
|
21
|
-
export { useRouteUtils } from "./hooks/useRouteUtils";
|
|
22
|
-
|
|
23
|
-
export { useRouterTransition } from "./hooks/useRouterTransition";
|
|
24
|
-
|
|
25
|
-
// Context
|
|
26
|
-
export { RouterProvider } from "./RouterProvider";
|
|
27
|
-
|
|
28
|
-
// Types
|
|
29
|
-
export type { LinkProps } from "./types";
|
|
30
|
-
|
|
31
|
-
export type { RouterErrorBoundaryProps } from "./components/RouterErrorBoundary";
|
|
32
|
-
|
|
33
|
-
export type { Navigator } from "@real-router/core";
|
|
34
|
-
|
|
35
|
-
export type { RouterTransitionSnapshot } from "@real-router/sources";
|
package/src/ssr.react-server.ts
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
// SSR-feature entry — type-only re-exports under `react-server` condition.
|
|
2
|
-
//
|
|
3
|
-
// Server Components that consume `<ClientOnly>`/`<ServerOnly>`/`<Await>`/
|
|
4
|
-
// `<Streamed>` props (e.g. for typing wrapper components rendered server-side)
|
|
5
|
-
// import the prop types from `@real-router/react/ssr`. Under the
|
|
6
|
-
// `react-server` condition this entry resolves to types only — no client
|
|
7
|
-
// runtime is pulled into the Server Component bundle.
|
|
8
|
-
|
|
9
|
-
export type { ClientOnlyProps } from "./components/ClientOnly";
|
|
10
|
-
|
|
11
|
-
export type { ServerOnlyProps } from "./components/ServerOnly";
|
|
12
|
-
|
|
13
|
-
export type { AwaitProps } from "./components/Await";
|
|
14
|
-
|
|
15
|
-
export type { StreamedProps } from "./components/Streamed";
|
|
16
|
-
|
|
17
|
-
export type { HttpStatusCodeProps } from "./components/HttpStatusCode";
|
|
18
|
-
|
|
19
|
-
export type { HttpStatusProviderProps } from "./components/HttpStatusProvider";
|
|
20
|
-
|
|
21
|
-
export type { HttpStatusSink } from "./utils/createHttpStatusSink";
|