clear-react-router 2.4.4 → 2.4.6

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 CHANGED
@@ -19,7 +19,7 @@ It provides first-class support for:
19
19
  * Simple, provider-free architecture
20
20
  * Small, explicit API
21
21
 
22
- > 👉 TL;DR? **[Try the live playground](https://clear-react-router.vercel.app/playground)** — no setup, click around.
22
+ > TL;DR? **[Try the live playground](https://clear-react-router.vercel.app/playground)** — no setup, click around.
23
23
 
24
24
 
25
25
  ## Features
@@ -39,6 +39,23 @@ It provides first-class support for:
39
39
  - **Browser History** - Full support for browser back/forward buttons
40
40
  - **Context-aware** - Pass and update context through routes
41
41
 
42
+ ## Deployment (static hosting)
43
+
44
+ The router uses the History API (`pushState` + `popstate`) exclusively — there is no hash mode.
45
+ Deep links and page refreshes therefore need an SPA fallback on static hosts: every path must serve `index.html`, otherwise refreshing e.g. `/about` returns 404.
46
+
47
+ Vercel (`vercel.json`):
48
+
49
+ ```json
50
+ { "rewrites": [{ "source": "/(.*)", "destination": "/index.html" }] }
51
+ ```
52
+
53
+ Netlify (`public/_redirects`):
54
+
55
+ ```text
56
+ /* /index.html 200
57
+ ```
58
+
42
59
  ## API
43
60
 
44
61
  ### `Router`
@@ -68,6 +85,8 @@ It provides first-class support for:
68
85
 
69
86
  ### `createRouter(routes)`
70
87
 
88
+ Required: `<Router>` expects the output of `createRouter` (`RouteItem[]` with built `pattern`s and resolved lazy components), not the raw config you write. Skipping it breaks nested-path matching and lazy preloading.
89
+
71
90
  Normalizes route configuration. Extracts dynamic params, builds nested paths.
72
91
 
73
92
  | Property | Type | Description |
@@ -125,6 +144,12 @@ If a route is both `optimistic` and has `gcTime` set, keep in mind the cached sn
125
144
 
126
145
  Component for client-side navigation with prefetch support, active state detection, and pending state styling. Prefetch includes lazy route component preload.
127
146
 
147
+ `Link` (like every router hook) works outside `<Router>` — all state lives in a global store, there is no React context. Only back/forward-button handling needs a mounted `<Router>`.
148
+
149
+ Rule of thumb: `to` for plain URLs, `path` + `params` when you want the pattern checked and segments URL-encoded.
150
+
151
+ Active matching: `'/'` matches only exactly `'/'`; any other target is active on exact match or — with the default `exact={false}` — on nested URLs too (`/settings` is active at `/settings/profile`).
152
+
128
153
  | Prop | Type | Default | Description |
129
154
  |------|------|---------|-------------|
130
155
  | `to` | `string` | required (unless `path` is set) | Target path as a raw URL. Mutually exclusive with `path` |
@@ -269,6 +294,8 @@ screen readers) intact:
269
294
  Reach for `as` only when the element itself must change (a `<button>`, a UI-kit component)
270
295
  — for looks alone, attributes + CSS are simpler and accessible by default.
271
296
 
297
+ ### Prefetch examples
298
+
272
299
  ```tsx
273
300
  // Global prefetch: hover with 100ms delay
274
301
  <Router routes={routes} defaultPrefetch="hover" defaultHoverPrefetchDelay={100} />
@@ -282,7 +309,11 @@ Reach for `as` only when the element itself must change (a `<button>`, a UI-kit
282
309
  <Link to="/admin" prefetch="none">
283
310
  Admin Panel
284
311
  </Link>
312
+ ```
285
313
 
314
+ ### Appearance and behavior examples
315
+
316
+ ```tsx
286
317
  // With custom active/pending classes
287
318
  <Link to="/settings" activeClassName="active-nav-link" pendingClassName="loading-nav-link">
288
319
  Settings
@@ -583,7 +614,7 @@ const App = () => <Router routes={routes} errorBoundary={ErrorBoundary} />
583
614
 
584
615
  ### `useNavigate()`
585
616
 
586
- Returns a function to navigate programmatically. Accepts a string (pathname, optionally with a `?query`), a `NavigationLocation` object, or `-1` to go back.
617
+ Returns a function to navigate programmatically. Accepts a string (pathname, optionally with a `?query`), a `NavigationLocation` object (`pathname`, or typed `path` + `params` — see below), or `-1` to go back.
587
618
 
588
619
  ```tsx
589
620
  type NavigationLocation = { pathname: string; search?: string | Record<string, string | number | boolean | null | undefined>; state?: unknown }
package/dist/index.d.ts CHANGED
@@ -14,5 +14,5 @@ export { useSubmitAction } from './hooks/useSubmitAction';
14
14
  export { useRestoreScroll } from './hooks/useRestoreScroll';
15
15
  export { createRouter } from './creators/createRouter';
16
16
  export { lazy } from './utils/lazy';
17
- export type { RouteItem, BlockerState, Location, RouterProps, NavigationLocation, NavigatePathArg, PathParams, ParamsFor, Status, } from './types';
17
+ export type { RouteItem, ClientRouteItem, BlockerState, Location, RouterProps, NavigationLocation, NavigatePathArg, PathParams, ParamsFor, Status, } from './types';
18
18
  export type { ElementProps, LinkProps } from './components/Link';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "clear-react-router",
3
- "version": "2.4.4",
3
+ "version": "2.4.6",
4
4
  "description": "A lightweight routing library for React applications",
5
5
  "author": "Andrew Bubnov",
6
6
  "scripts": {