@real-router/core 0.27.0 → 0.29.0
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/README.md +42 -16
- package/dist/cjs/index.js +1 -1
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/metafile-cjs.json +1 -1
- package/dist/esm/index.mjs +1 -1
- package/dist/esm/index.mjs.map +1 -1
- package/dist/esm/metafile-esm.json +1 -1
- package/package.json +3 -3
- package/src/Router.ts +3 -0
- package/src/api/getPluginApi.ts +0 -1
- package/src/api/getRoutesApi.ts +75 -0
- package/src/internals.ts +1 -0
- package/src/namespaces/NavigationNamespace/NavigationNamespace.ts +4 -3
- package/src/namespaces/NavigationNamespace/transition/index.ts +1 -0
- package/src/namespaces/NavigationNamespace/types.ts +1 -1
- package/src/namespaces/RouteLifecycleNamespace/RouteLifecycleNamespace.ts +96 -0
- package/src/namespaces/RouterLifecycleNamespace/RouterLifecycleNamespace.ts +2 -2
- package/src/namespaces/RouterLifecycleNamespace/types.ts +3 -8
- package/src/namespaces/RoutesNamespace/RoutesNamespace.ts +1 -4
- package/src/namespaces/RoutesNamespace/routesStore.ts +11 -2
- package/src/namespaces/StateNamespace/StateNamespace.ts +2 -9
- package/src/transitionPath.ts +4 -12
- package/src/wiring/RouterWiringBuilder.ts +5 -6
|
@@ -1,16 +1,11 @@
|
|
|
1
1
|
// packages/core/src/namespaces/RouterLifecycleNamespace/types.ts
|
|
2
2
|
|
|
3
|
-
import type {
|
|
4
|
-
NavigationOptions,
|
|
5
|
-
Options,
|
|
6
|
-
Params,
|
|
7
|
-
State,
|
|
8
|
-
} from "@real-router/types";
|
|
3
|
+
import type { Options, Params, State } from "@real-router/types";
|
|
9
4
|
|
|
10
5
|
export interface RouterLifecycleDependencies {
|
|
11
6
|
getOptions: () => Options;
|
|
12
|
-
makeNotFoundState: (path: string
|
|
13
|
-
|
|
7
|
+
makeNotFoundState: (path: string) => State;
|
|
8
|
+
clearState: () => void;
|
|
14
9
|
matchPath: <P extends Params = Params, MP extends Params = Params>(
|
|
15
10
|
path: string,
|
|
16
11
|
) => State<P, MP> | undefined;
|
|
@@ -30,8 +30,6 @@ import type {
|
|
|
30
30
|
RouteTreeState,
|
|
31
31
|
} from "route-tree";
|
|
32
32
|
|
|
33
|
-
const EMPTY_OPTIONS = Object.freeze({});
|
|
34
|
-
|
|
35
33
|
function collectUrlParamsArray(segments: readonly RouteTree[]): string[] {
|
|
36
34
|
const params: string[] = [];
|
|
37
35
|
|
|
@@ -106,7 +104,7 @@ export class RoutesNamespace<
|
|
|
106
104
|
);
|
|
107
105
|
}
|
|
108
106
|
|
|
109
|
-
if (toState.
|
|
107
|
+
if (toState.transition?.reload) {
|
|
110
108
|
return true;
|
|
111
109
|
}
|
|
112
110
|
|
|
@@ -270,7 +268,6 @@ export class RoutesNamespace<
|
|
|
270
268
|
|
|
271
269
|
return this.#deps.makeState<P, MP>(routeName, routeParams, builtPath, {
|
|
272
270
|
params: meta as MP,
|
|
273
|
-
options: EMPTY_OPTIONS,
|
|
274
271
|
});
|
|
275
272
|
}
|
|
276
273
|
|
|
@@ -108,6 +108,17 @@ export function rebuildTreeInPlace<
|
|
|
108
108
|
*/
|
|
109
109
|
export function resetStore<
|
|
110
110
|
Dependencies extends DefaultDependencies = DefaultDependencies,
|
|
111
|
+
>(store: RoutesStore<Dependencies>): void {
|
|
112
|
+
clearRouteData(store);
|
|
113
|
+
rebuildTreeInPlace(store);
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* Clears route data without rebuilding the tree.
|
|
118
|
+
* Used by replace() to avoid double rebuild (clearRouteData + commitTreeChanges).
|
|
119
|
+
*/
|
|
120
|
+
export function clearRouteData<
|
|
121
|
+
Dependencies extends DefaultDependencies = DefaultDependencies,
|
|
111
122
|
>(store: RoutesStore<Dependencies>): void {
|
|
112
123
|
store.definitions.length = 0;
|
|
113
124
|
|
|
@@ -118,8 +129,6 @@ export function resetStore<
|
|
|
118
129
|
string,
|
|
119
130
|
Record<string, unknown>
|
|
120
131
|
>;
|
|
121
|
-
|
|
122
|
-
rebuildTreeInPlace(store);
|
|
123
132
|
}
|
|
124
133
|
|
|
125
134
|
// =============================================================================
|
|
@@ -7,12 +7,7 @@ import { constants } from "../../constants";
|
|
|
7
7
|
import { freezeStateInPlace } from "../../helpers";
|
|
8
8
|
|
|
9
9
|
import type { StateNamespaceDependencies } from "./types";
|
|
10
|
-
import type {
|
|
11
|
-
NavigationOptions,
|
|
12
|
-
Params,
|
|
13
|
-
State,
|
|
14
|
-
StateMetaInput,
|
|
15
|
-
} from "@real-router/types";
|
|
10
|
+
import type { Params, State, StateMetaInput } from "@real-router/types";
|
|
16
11
|
import type { RouteTreeStateMeta } from "route-tree";
|
|
17
12
|
|
|
18
13
|
/**
|
|
@@ -158,7 +153,6 @@ export class StateNamespace {
|
|
|
158
153
|
...meta,
|
|
159
154
|
id: forceId ?? ++this.#stateId,
|
|
160
155
|
params: meta.params,
|
|
161
|
-
options: meta.options,
|
|
162
156
|
}
|
|
163
157
|
: undefined;
|
|
164
158
|
|
|
@@ -190,13 +184,12 @@ export class StateNamespace {
|
|
|
190
184
|
/**
|
|
191
185
|
* Creates a frozen state object for the "not found" route.
|
|
192
186
|
*/
|
|
193
|
-
makeNotFoundState(path: string
|
|
187
|
+
makeNotFoundState(path: string): State {
|
|
194
188
|
return this.makeState<{ path: string }>(
|
|
195
189
|
constants.UNKNOWN_ROUTE,
|
|
196
190
|
{ path },
|
|
197
191
|
path,
|
|
198
192
|
{
|
|
199
|
-
options,
|
|
200
193
|
params: {},
|
|
201
194
|
},
|
|
202
195
|
);
|
package/src/transitionPath.ts
CHANGED
|
@@ -333,18 +333,6 @@ function computeTransitionPath(
|
|
|
333
333
|
};
|
|
334
334
|
}
|
|
335
335
|
|
|
336
|
-
const toStateOptions = toState.meta?.options ?? {};
|
|
337
|
-
|
|
338
|
-
// ===== FAST PATH 2: Force reload =====
|
|
339
|
-
// Skip all optimization when reload is requested
|
|
340
|
-
if (toStateOptions.reload) {
|
|
341
|
-
return {
|
|
342
|
-
intersection: EMPTY_INTERSECTION,
|
|
343
|
-
toActivate: nameToIDs(toState.name),
|
|
344
|
-
toDeactivate: reverseArray(nameToIDs(fromState.name)),
|
|
345
|
-
};
|
|
346
|
-
}
|
|
347
|
-
|
|
348
336
|
// ===== FAST PATH 3: Missing meta or meta.params requires full reload =====
|
|
349
337
|
// Check if meta or meta.params is actually missing (not just empty)
|
|
350
338
|
const toHasMeta = toState.meta?.params !== undefined;
|
|
@@ -399,7 +387,11 @@ function computeTransitionPath(
|
|
|
399
387
|
export function getTransitionPath(
|
|
400
388
|
toState: State,
|
|
401
389
|
fromState?: State,
|
|
390
|
+
opts?: { reload?: boolean },
|
|
402
391
|
): TransitionPath {
|
|
392
|
+
if (opts?.reload) {
|
|
393
|
+
return computeTransitionPath(toState, fromState);
|
|
394
|
+
}
|
|
403
395
|
if (
|
|
404
396
|
cachedResult !== null &&
|
|
405
397
|
toState === cachedToState &&
|
|
@@ -69,10 +69,10 @@ export class RouterWiringBuilder<
|
|
|
69
69
|
wireRoutesDeps(): void {
|
|
70
70
|
const routesDeps: RoutesDependencies<Dependencies> = {
|
|
71
71
|
addActivateGuard: (name, handler) => {
|
|
72
|
-
this.routeLifecycle.addCanActivate(name, handler, true);
|
|
72
|
+
this.routeLifecycle.addCanActivate(name, handler, true, true);
|
|
73
73
|
},
|
|
74
74
|
addDeactivateGuard: (name, handler) => {
|
|
75
|
-
this.routeLifecycle.addCanDeactivate(name, handler, true);
|
|
75
|
+
this.routeLifecycle.addCanDeactivate(name, handler, true, true);
|
|
76
76
|
},
|
|
77
77
|
makeState: (name, params, path, meta) =>
|
|
78
78
|
this.state.makeState(name, params, path, meta),
|
|
@@ -177,10 +177,9 @@ export class RouterWiringBuilder<
|
|
|
177
177
|
wireLifecycleDeps(): void {
|
|
178
178
|
const lifecycleDeps: RouterLifecycleDependencies = {
|
|
179
179
|
getOptions: () => this.options.get(),
|
|
180
|
-
makeNotFoundState: (path
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
this.state.set(state);
|
|
180
|
+
makeNotFoundState: (path) => this.state.makeNotFoundState(path),
|
|
181
|
+
clearState: () => {
|
|
182
|
+
this.state.set(undefined);
|
|
184
183
|
},
|
|
185
184
|
matchPath: (path) => this.routes.matchPath(path, this.options.get()),
|
|
186
185
|
completeStart: () => {
|