clear-react-router 2.6.2 → 2.6.3
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 +4 -0
- package/dist/index.js +11 -6
- package/dist/runtime/navigate.d.ts +3 -1
- package/dist/types.d.ts +7 -1
- package/dist/utils/commitState.d.ts +2 -1
- package/package.json +1 -1
- package/skills/getting-started/SKILL.md +3 -1
package/README.md
CHANGED
|
@@ -814,15 +814,19 @@ type NavigationLocation = {
|
|
|
814
814
|
pathname: string;
|
|
815
815
|
search?: string | Record<string, string | number | boolean | null | undefined>;
|
|
816
816
|
state?: unknown;
|
|
817
|
+
replace?: boolean; // rewrite the current history entry instead of pushing a new one
|
|
817
818
|
};
|
|
818
819
|
|
|
819
820
|
const navigate = useNavigate();
|
|
820
821
|
|
|
821
822
|
navigate('/about'); // string
|
|
822
823
|
navigate({ pathname: '/user/123', search: { user: 'Jane Doe' }, state: { from: 'home' } }); // NavigationLocation
|
|
824
|
+
navigate({ pathname: '/dashboard', replace: true }); // e.g. after login, so /login stays out of history
|
|
823
825
|
navigate(-1); // go back
|
|
824
826
|
```
|
|
825
827
|
|
|
828
|
+
Redirects declared in `beforeLoad` (`redirect(...)`) always rewrite the current history entry — the user never saw the intermediate URL, so the Back button must not return into the redirect loop.
|
|
829
|
+
|
|
826
830
|
**Note:** Navigation state can be accessed via [`useLocation()`](#uselocation):
|
|
827
831
|
|
|
828
832
|
```tsx
|
package/dist/index.js
CHANGED
|
@@ -113,7 +113,7 @@ var handleBackgroundFailure = (loaderMap, path, error, routeItem, displayedData,
|
|
|
113
113
|
};
|
|
114
114
|
//#endregion
|
|
115
115
|
//#region utils/commitState.ts
|
|
116
|
-
var createCommitState = ({ routeDataState, blockerState }) => ({ routeItem, loaderStateValue, location }) => {
|
|
116
|
+
var createCommitState = ({ routeDataState, blockerState }) => ({ routeItem, loaderStateValue, location, replace }) => {
|
|
117
117
|
const isError = loaderStateValue.loaderError || loaderStateValue.beforeLoadError;
|
|
118
118
|
routeDataState.setState({
|
|
119
119
|
routeItem,
|
|
@@ -123,7 +123,8 @@ var createCommitState = ({ routeDataState, blockerState }) => ({ routeItem, load
|
|
|
123
123
|
});
|
|
124
124
|
if (blockerState.getState() === "blocked") blockerState.setState("unblocked");
|
|
125
125
|
if ((location.search ? `${location.pathname}${location.search}` : location.pathname) === window.location.pathname + window.location.search) return;
|
|
126
|
-
history.
|
|
126
|
+
if (replace) history.replaceState(location.state ?? null, "", `${location.pathname}${location.search}`);
|
|
127
|
+
else history.pushState(location.state ?? null, "", `${location.pathname}${location.search}`);
|
|
127
128
|
};
|
|
128
129
|
//#endregion
|
|
129
130
|
//#region utils/commitNavigation.ts
|
|
@@ -303,12 +304,14 @@ var createNavigate = (routerState, revalidateCache, syncCacheSnapshot) => {
|
|
|
303
304
|
return await navigate({
|
|
304
305
|
pathname,
|
|
305
306
|
search,
|
|
306
|
-
prevLocation
|
|
307
|
+
prevLocation,
|
|
308
|
+
replace: true
|
|
307
309
|
});
|
|
308
310
|
}
|
|
309
311
|
return await navigate({
|
|
310
312
|
...redirected,
|
|
311
|
-
prevLocation
|
|
313
|
+
prevLocation,
|
|
314
|
+
replace: true
|
|
312
315
|
});
|
|
313
316
|
};
|
|
314
317
|
try {
|
|
@@ -476,8 +479,9 @@ var createNavigate = (routerState, revalidateCache, syncCacheSnapshot) => {
|
|
|
476
479
|
});
|
|
477
480
|
};
|
|
478
481
|
const navigate = async (rawLocation) => {
|
|
482
|
+
const { replace: replaceEntry, ...locationFields } = rawLocation;
|
|
479
483
|
const nextLocation = {
|
|
480
|
-
...
|
|
484
|
+
...locationFields,
|
|
481
485
|
search: rawLocation.search ?? ""
|
|
482
486
|
};
|
|
483
487
|
if (checkBlocked(nextLocation)) return;
|
|
@@ -502,7 +506,8 @@ var createNavigate = (routerState, revalidateCache, syncCacheSnapshot) => {
|
|
|
502
506
|
commitNavigation(() => commitState({
|
|
503
507
|
location: nextLocation,
|
|
504
508
|
routeItem: nextItem,
|
|
505
|
-
loaderStateValue
|
|
509
|
+
loaderStateValue,
|
|
510
|
+
replace: replaceEntry === true
|
|
506
511
|
}));
|
|
507
512
|
clearCurrentGcTimeout(nextItem, nextLocation);
|
|
508
513
|
afterLoad(nextItem, nextLocation, params);
|
|
@@ -1,2 +1,4 @@
|
|
|
1
1
|
import { Location, RevalidateCache, RouterState } from '../types';
|
|
2
|
-
export declare const createNavigate: (routerState: RouterState, revalidateCache: RevalidateCache, syncCacheSnapshot: () => void) => (rawLocation: Location
|
|
2
|
+
export declare const createNavigate: (routerState: RouterState, revalidateCache: RevalidateCache, syncCacheSnapshot: () => void) => (rawLocation: Location & {
|
|
3
|
+
replace?: boolean;
|
|
4
|
+
}) => Promise<void>;
|
package/dist/types.d.ts
CHANGED
|
@@ -179,7 +179,9 @@ export type RouterState = {
|
|
|
179
179
|
};
|
|
180
180
|
export type RouterType = {
|
|
181
181
|
runtime: {
|
|
182
|
-
navigate(arg: Location
|
|
182
|
+
navigate(arg: Location & {
|
|
183
|
+
replace?: boolean;
|
|
184
|
+
}): Promise<void>;
|
|
183
185
|
invalidate(pathList?: string | string[], options?: InvalidateOptions): Promise<InvalidateResult[]>;
|
|
184
186
|
prefetch(location: Location, signal?: AbortSignal): Promise<void>;
|
|
185
187
|
syncCacheSnapshot(): void;
|
|
@@ -222,6 +224,8 @@ export type InvalidateResult = {
|
|
|
222
224
|
export type SearchObject = Record<string, string | number | boolean | null | undefined>;
|
|
223
225
|
export type NavigationLocation = Omit<Location, 'search'> & {
|
|
224
226
|
search?: string | SearchObject;
|
|
227
|
+
/** Rewrite the current history entry instead of pushing a new one. */
|
|
228
|
+
replace?: boolean;
|
|
225
229
|
};
|
|
226
230
|
export type PathParams = Record<string, string | number>;
|
|
227
231
|
export type ParamsFor<TPath extends string> = TPath extends `${string}:${infer Param}/${infer Rest}` ? {
|
|
@@ -275,6 +279,8 @@ export type NavigatePathInput = {
|
|
|
275
279
|
params?: PathParams;
|
|
276
280
|
search?: string | SearchObject;
|
|
277
281
|
state?: unknown;
|
|
282
|
+
/** Rewrite the current history entry instead of pushing a new one. */
|
|
283
|
+
replace?: boolean;
|
|
278
284
|
};
|
|
279
285
|
export type Synchronizer = <T>(subscribe: (updater: () => void) => () => void, getSnapshot: () => T, getServerSnapshot?: () => T) => T;
|
|
280
286
|
export {};
|
|
@@ -3,6 +3,7 @@ type CommitState = {
|
|
|
3
3
|
location: Location;
|
|
4
4
|
loaderStateValue: LoaderState;
|
|
5
5
|
routeItem?: RouteItem;
|
|
6
|
+
replace?: boolean;
|
|
6
7
|
};
|
|
7
|
-
export declare const createCommitState: ({ routeDataState, blockerState }: RouterState) => ({ routeItem, loaderStateValue, location }: CommitState) => void;
|
|
8
|
+
export declare const createCommitState: ({ routeDataState, blockerState }: RouterState) => ({ routeItem, loaderStateValue, location, replace }: CommitState) => void;
|
|
8
9
|
export {};
|
package/package.json
CHANGED
|
@@ -60,7 +60,9 @@ navigate({ path: '/users/:userId', params: { userId: '42' } }); // typed templat
|
|
|
60
60
|
The whole surface, one line each — details live in the references (load by task
|
|
61
61
|
below):
|
|
62
62
|
|
|
63
|
-
- **Routing** —
|
|
63
|
+
- **Routing** — `replace?: boolean` on any navigation rewrites the current history
|
|
64
|
+
entry (post-login flows); redirects declared in `beforeLoad` always rewrite the
|
|
65
|
+
current entry, so Back never returns into a redirect loop. Object routes with nested `children` (relative paths), `layout` /
|
|
64
66
|
`layouts` nesting (outermost-first, inherited), lazy `element`s, catch-all `*`,
|
|
65
67
|
typed path templates in `Link` (`path` + `params`) and `useNavigate`, active-link
|
|
66
68
|
matching with `exact`, custom element rendering via `as`.
|