clear-react-router 1.4.1 → 1.4.2
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 +1 -1
- package/dist/index.js +20 -9
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -79,7 +79,7 @@ Renders the current route's component. Must be placed inside `<RouterProvider>`.
|
|
|
79
79
|
</RouterProvider>
|
|
80
80
|
```
|
|
81
81
|
|
|
82
|
-
> **Note:** When `isAnimated` is enabled, `loaderFallback` is not shown. Instead, a small spinner appears (if `spinner={true}`).
|
|
82
|
+
> **Note:** When `isAnimated` is enabled, `loaderFallback` is not shown. Instead, a small spinner appears (if `spinner={true}`). On the initial page load, however, the route's loaderFallback is rendered if available.
|
|
83
83
|
|
|
84
84
|
### `Link`
|
|
85
85
|
|
package/dist/index.js
CHANGED
|
@@ -500,7 +500,6 @@ var renderElement = (Component) => {
|
|
|
500
500
|
};
|
|
501
501
|
//#endregion
|
|
502
502
|
//#region components/Router.tsx
|
|
503
|
-
var PAGE_NOT_FOUND = "error 404. Page not found";
|
|
504
503
|
var ALL_LOCATIONS = "*";
|
|
505
504
|
var Router = ({ spinner = true }) => {
|
|
506
505
|
const { location, isLoading } = useNavigationState();
|
|
@@ -510,15 +509,27 @@ var Router = ({ spinner = true }) => {
|
|
|
510
509
|
if (!location.pathname) return void 0;
|
|
511
510
|
return routeList.find((el) => el.path === ALL_LOCATIONS || comparePaths(el, location.pathname));
|
|
512
511
|
}, [location.pathname, routeList]);
|
|
513
|
-
const
|
|
512
|
+
const pendingRoute = useMemo(() => {
|
|
513
|
+
if (location.pathname) return void 0;
|
|
514
|
+
return routeList.find((el) => comparePaths(el, window.location.pathname));
|
|
515
|
+
}, [location.pathname, routeList]);
|
|
516
|
+
const params = useMemo(() => {
|
|
517
|
+
return getParamsObject({
|
|
518
|
+
routeItem: routeItem || pendingRoute,
|
|
519
|
+
pathname: location.pathname || window.location.pathname
|
|
520
|
+
});
|
|
521
|
+
}, [
|
|
522
|
+
location.pathname,
|
|
514
523
|
routeItem,
|
|
515
|
-
|
|
516
|
-
|
|
524
|
+
pendingRoute
|
|
525
|
+
]);
|
|
517
526
|
const shouldErrorElementShown = useMemo(() => Boolean(loaderState[location.pathname]?.loaderError || loaderState[location.pathname]?.beforeLoadError), [loaderState, location.pathname]);
|
|
518
|
-
if (
|
|
519
|
-
if (!routeItem &&
|
|
520
|
-
|
|
521
|
-
|
|
527
|
+
if (!routeItem && !pendingRoute) return null;
|
|
528
|
+
if (!routeItem && pendingRoute) return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ViewProvider, {
|
|
529
|
+
params,
|
|
530
|
+
children: renderElement(pendingRoute?.loaderFallback)
|
|
531
|
+
});
|
|
532
|
+
if (!isAnimated && !shouldErrorElementShown && isLoading) return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ViewProvider, {
|
|
522
533
|
params,
|
|
523
534
|
children: renderElement(routeItem?.loaderFallback)
|
|
524
535
|
});
|
|
@@ -530,7 +541,7 @@ var Router = ({ spinner = true }) => {
|
|
|
530
541
|
style: { viewTransitionName: "page" },
|
|
531
542
|
children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(ViewProvider, {
|
|
532
543
|
params,
|
|
533
|
-
children: [renderElement(routeItem?.element) ||
|
|
544
|
+
children: [renderElement(routeItem?.element) || null, spinner && isAnimated && isLoading && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Spinner, {})]
|
|
534
545
|
})
|
|
535
546
|
});
|
|
536
547
|
};
|