clear-react-router 1.3.4 → 1.3.5
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 +16 -4
- package/dist/hooks/useHistoricalTrail.d.ts +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +15 -1
- package/package.json +11 -2
package/README.md
CHANGED
|
@@ -327,13 +327,25 @@ function ProductFilter() {
|
|
|
327
327
|
|
|
328
328
|
**Key features:**
|
|
329
329
|
|
|
330
|
-
-
|
|
331
|
-
-
|
|
332
|
-
-
|
|
333
|
-
-
|
|
330
|
+
- **Array support** — `getSearchParams` returns `string[]` when multiple values exist for the same key
|
|
331
|
+
- **Functional updates** — Update parameters based on previous state without losing other params
|
|
332
|
+
- **Type-safe** — Proper TypeScript support with overloads
|
|
333
|
+
- **Stable reference** — `setSearchParams` reference is stable and safe to use in `useEffect`
|
|
334
334
|
|
|
335
335
|
> **Note:** `getSearchParams` returns `string` for single values, `string[]` for multiple values, and `''` if the key is not found.
|
|
336
336
|
|
|
337
|
+
### `useHistoricalTrail()`
|
|
338
|
+
|
|
339
|
+
Returns an array of pathnames representing the user's actual navigation history. Perfect for **history-based breadcrumbs** in dashboards, admin panels, multi-step forms, or any app where users navigate non-linearly.
|
|
340
|
+
|
|
341
|
+
**Returns:** Array of pathnames in chronological visit order (e.g., `['/dashboard', '/users', '/settings']`)
|
|
342
|
+
|
|
343
|
+
**Key features:**
|
|
344
|
+
- **Chronological order** — Paths are stored in the order the user visited them
|
|
345
|
+
- **Unique entries** — Revisiting a page trims the trail to that point
|
|
346
|
+
- **Respects navigation blocking** — Only successful navigations are added
|
|
347
|
+
- **Redirect-safe** — Redirected pages are not added to the trail
|
|
348
|
+
|
|
337
349
|
## Lazy Loading
|
|
338
350
|
|
|
339
351
|
Clear Router supports code-splitting out of the box. Simply pass a function that returns a dynamic import:
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const useHistoricalTrail: () => string[];
|
package/dist/index.d.ts
CHANGED
|
@@ -9,5 +9,6 @@ export { useBlocker } from './hooks/useBlocker';
|
|
|
9
9
|
export { useBeforeUnload } from './hooks/useBeforeUnload';
|
|
10
10
|
export { useRouterContext } from './hooks/useRouterContext';
|
|
11
11
|
export { useSearchParams } from './hooks/useSearchParams';
|
|
12
|
+
export { useHistoricalTrail } from './hooks/useHistoricalTrail';
|
|
12
13
|
export { createRouter } from './utils/utils';
|
|
13
14
|
export type { RouteItem, BlockerState, Location } from './types/global';
|
package/dist/index.js
CHANGED
|
@@ -642,4 +642,18 @@ var useSearchParams = () => {
|
|
|
642
642
|
};
|
|
643
643
|
};
|
|
644
644
|
//#endregion
|
|
645
|
-
|
|
645
|
+
//#region hooks/useHistoricalTrail.ts
|
|
646
|
+
var useHistoricalTrail = () => {
|
|
647
|
+
const { pathname } = useLocation();
|
|
648
|
+
const [trail, setTrail] = useState([]);
|
|
649
|
+
useEffect(() => {
|
|
650
|
+
if (!pathname) return;
|
|
651
|
+
setTrail((prevState) => {
|
|
652
|
+
const index = prevState.indexOf(pathname);
|
|
653
|
+
return index === -1 ? [...prevState, pathname] : prevState.slice(0, index + 1);
|
|
654
|
+
});
|
|
655
|
+
}, [pathname]);
|
|
656
|
+
return trail;
|
|
657
|
+
};
|
|
658
|
+
//#endregion
|
|
659
|
+
export { Link, Router, RouterProvider, createRouter, useBeforeUnload, useBlocker, useHistoricalTrail, useLoaderState, useLocation, useNavigate, useParams, useRouterContext, useSearchParams };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "clear-react-router",
|
|
3
|
-
"version": "1.3.
|
|
3
|
+
"version": "1.3.5",
|
|
4
4
|
"description": "A lightweight, type-safe routing library for React applications",
|
|
5
5
|
"author": "Andrew Bubnov",
|
|
6
6
|
"scripts": {
|
|
@@ -12,7 +12,16 @@
|
|
|
12
12
|
"routing",
|
|
13
13
|
"typescript",
|
|
14
14
|
"spa",
|
|
15
|
-
"nested-routes"
|
|
15
|
+
"nested-routes",
|
|
16
|
+
"data-loading",
|
|
17
|
+
"navigation-blocker",
|
|
18
|
+
"scroll-restoration",
|
|
19
|
+
"breadcrumbs",
|
|
20
|
+
"search-params",
|
|
21
|
+
"lazy-loading",
|
|
22
|
+
"prefetching",
|
|
23
|
+
"view-transitions",
|
|
24
|
+
"animations"
|
|
16
25
|
],
|
|
17
26
|
"repository": {
|
|
18
27
|
"type": "git",
|