clear-react-router 1.7.2 → 1.7.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 CHANGED
@@ -50,8 +50,8 @@ Normalizes route configuration. Handles wildcard `*` routes, extracts dynamic pa
50
50
  | `loader` | `({ params, context, setContext }) => Promise<unknown>` | Fetch data using route params and context. Can update context via `setContext` |
51
51
  | `afterLoad` | `({ params, context, setContext }) => Promise<void>` | Analytics, side effects after data is loaded. Can update context via `setContext` |
52
52
  | `fallback` | `ReactElement \| () => ReactElement` | Loading fallback (for lazy loading) |
53
- | `loaderFallback` | `ReactElement \| () => ReactElement` | Loading fallback (for loader) |
54
- | `errorElement` | `ReactElement \| () => ReactElement` | Error fallback |
53
+ | `loaderFallback` | `ReactElement \| () => ReactElement` | Loading fallback for the route's `loader`. Overrides the global `defaultLoaderFallback` set in `Router` |
54
+ | `errorElement` | `ReactElement \| () => ReactElement` | Error fallback for the route. Overrides the global `defaultErrorElement` set in `Router` |
55
55
  | `staleTime` | `number` | Time in ms before cached data is considered stale and re-fetched in the background. If not provided, data never expires (cached forever) |
56
56
  | `actions` | `({ params, context, invalidate, setContext }) => Record<string, (formData: FormData) => unknown \| Promise<unknown>>` | Defines route actions for data mutations. Actions receive `FormData`, can update context via `setContext`, and can refresh loader data using the router-provided `invalidate`. |
57
57
 
@@ -62,6 +62,8 @@ Normalizes route configuration. Handles wildcard `*` routes, extracts dynamic pa
62
62
  | `routes` | `RouteItem[]` | required | Array of route configurations |
63
63
  | `isAnimated` | `boolean \| undefined` | `false` | Enable smooth page fade transitions |
64
64
  | `animationDuration` | `number` | `optional` | Animation duration in milliseconds (browser default is used if not set) |
65
+ | `defaultLoaderFallback` | `ReactElement \| () => ReactElement` | `optional` | Default loading fallback for every route loader |
66
+ | `defaultErrorElement` | `ReactElement \| () => ReactElement` | `optional` | Default error fallback for every route |
65
67
  | `spinner` | `boolean \| undefined` | `true` | Show a small spinner in the corner while loading data (only when `isAnimated` is enabled) |
66
68
  | `preserveScroll` | `boolean \| undefined` | `true` | Save and restore scroll position when navigating between pages |
67
69
  | `showFallbackOnAnimation` | `boolean \| undefined` | `false` | Show `loaderFallback` even when `isAnimated` is `true` (instead of spinner) |
@@ -1,2 +1,2 @@
1
1
  import { RouterProps } from '../types/global';
2
- export declare const Router: ({ routes, animationDuration, isAnimated, spinner, preserveScroll, showFallbackOnAnimation, prefetch, hoverPrefetchDelay, errorBoundary: ErrorBoundary, context: initialContext, }: RouterProps) => import("react/jsx-runtime").JSX.Element | null;
2
+ export declare const Router: ({ routes, animationDuration, isAnimated, spinner, preserveScroll, showFallbackOnAnimation, prefetch, hoverPrefetchDelay, errorBoundary: ErrorBoundary, context: initialContext, defaultLoaderFallback, defaultErrorElement, }: RouterProps) => import("react/jsx-runtime").JSX.Element | null;
package/dist/index.js CHANGED
@@ -557,7 +557,7 @@ var renderElement = (Component) => {
557
557
  //#endregion
558
558
  //#region components/Router.tsx
559
559
  var EmptyBoundary = ({ children }) => children;
560
- var Router = ({ routes, animationDuration, isAnimated = false, spinner = true, preserveScroll = true, showFallbackOnAnimation = false, prefetch = "hover", hoverPrefetchDelay = 150, errorBoundary: ErrorBoundary = EmptyBoundary, context: initialContext }) => {
560
+ var Router = ({ routes, animationDuration, isAnimated = false, spinner = true, preserveScroll = true, showFallbackOnAnimation = false, prefetch = "hover", hoverPrefetchDelay = 150, errorBoundary: ErrorBoundary = EmptyBoundary, context: initialContext, defaultLoaderFallback, defaultErrorElement }) => {
561
561
  const [isLoading] = useIsLoading();
562
562
  const [currentLoaderFallback] = useLoaderFallback();
563
563
  const [routeItemData] = useRouteItemData();
@@ -588,10 +588,10 @@ var Router = ({ routes, animationDuration, isAnimated = false, spinner = true, p
588
588
  const showSpinner = spinner && isAnimated && isLoading;
589
589
  const loadingContent = !showErrorElement && isLoading;
590
590
  const { routeItem, location } = routeItemData;
591
- if ((showFallbackOnAnimation || !isAnimated) && loadingContent) return renderElement(currentLoaderFallback);
591
+ if ((showFallbackOnAnimation || !isAnimated) && loadingContent) return renderElement(currentLoaderFallback || defaultLoaderFallback);
592
592
  if (!showFallbackOnAnimation && isAnimated && loadingContent) return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Spinner, {});
593
593
  if (!routeItem) return null;
594
- if (showErrorElement) return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [renderElement(routeItem.errorElement), showSpinner && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Spinner, {})] });
594
+ if (showErrorElement) return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [renderElement(routeItem.errorElement || defaultErrorElement), showSpinner && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Spinner, {})] });
595
595
  return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", {
596
596
  style: { viewTransitionName: "page" },
597
597
  children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)(ErrorBoundary, { children: renderElement(routeItem.element) }, location.pathname), showSpinner && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Spinner, {})]
@@ -71,6 +71,8 @@ export type RouterProps = {
71
71
  animationDuration?: number;
72
72
  spinner?: boolean;
73
73
  preserveScroll?: boolean;
74
+ defaultLoaderFallback?: Element;
75
+ defaultErrorElement?: Element;
74
76
  showFallbackOnAnimation?: boolean;
75
77
  prefetch?: 'hover' | 'render' | 'viewport' | 'none';
76
78
  hoverPrefetchDelay?: number;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "clear-react-router",
3
- "version": "1.7.2",
3
+ "version": "1.7.3",
4
4
  "description": "A lightweight, type-safe routing library for React applications",
5
5
  "author": "Andrew Bubnov",
6
6
  "scripts": {