@fictjs/router 0.17.0 → 0.17.1

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/dist/index.d.cts CHANGED
@@ -419,6 +419,7 @@ declare function StaticRouter(props: StaticRouterProps & {
419
419
  }): FictNode;
420
420
  interface RoutesProps {
421
421
  children?: FictNode;
422
+ routes?: RouteDefinition[];
422
423
  }
423
424
  /**
424
425
  * Routes component - renders the matched route
package/dist/index.d.ts CHANGED
@@ -419,6 +419,7 @@ declare function StaticRouter(props: StaticRouterProps & {
419
419
  }): FictNode;
420
420
  interface RoutesProps {
421
421
  children?: FictNode;
422
+ routes?: RouteDefinition[];
422
423
  }
423
424
  /**
424
425
  * Routes component - renders the matched route
package/dist/index.js CHANGED
@@ -1504,13 +1504,13 @@ import { Fragment as Fragment2, jsx as jsx2 } from "fict/jsx-runtime";
1504
1504
  function Router(props) {
1505
1505
  const history2 = props.history || createBrowserHistory();
1506
1506
  const routes = extractRoutes(props.children);
1507
- return /* @__PURE__ */ jsx2(RouterProvider, { history: history2, routes, base: props.base, children: /* @__PURE__ */ jsx2(Routes, { children: props.children }) });
1507
+ return /* @__PURE__ */ jsx2(RouterProvider, { history: history2, routes, base: props.base, children: /* @__PURE__ */ jsx2(Routes, { routes, children: props.children }) });
1508
1508
  }
1509
1509
  function HashRouter(props) {
1510
1510
  const hashOptions = props.hashType ? { hashType: props.hashType } : void 0;
1511
1511
  const history2 = createHashHistory(hashOptions);
1512
1512
  const routes = extractRoutes(props.children);
1513
- return /* @__PURE__ */ jsx2(RouterProvider, { history: history2, routes, base: props.base, children: /* @__PURE__ */ jsx2(Routes, { children: props.children }) });
1513
+ return /* @__PURE__ */ jsx2(RouterProvider, { history: history2, routes, base: props.base, children: /* @__PURE__ */ jsx2(Routes, { routes, children: props.children }) });
1514
1514
  }
1515
1515
  function MemoryRouter(props) {
1516
1516
  const memoryOptions = {};
@@ -1524,17 +1524,17 @@ function MemoryRouter(props) {
1524
1524
  Object.keys(memoryOptions).length > 0 ? memoryOptions : void 0
1525
1525
  );
1526
1526
  const routes = extractRoutes(props.children);
1527
- return /* @__PURE__ */ jsx2(RouterProvider, { history: history2, routes, base: props.base, children: /* @__PURE__ */ jsx2(Routes, { children: props.children }) });
1527
+ return /* @__PURE__ */ jsx2(RouterProvider, { history: history2, routes, base: props.base, children: /* @__PURE__ */ jsx2(Routes, { routes, children: props.children }) });
1528
1528
  }
1529
1529
  function StaticRouter(props) {
1530
1530
  const history2 = createStaticHistory(props.url);
1531
1531
  const routes = extractRoutes(props.children);
1532
- return /* @__PURE__ */ jsx2(RouterProvider, { history: history2, routes, base: props.base, children: /* @__PURE__ */ jsx2(Routes, { children: props.children }) });
1532
+ return /* @__PURE__ */ jsx2(RouterProvider, { history: history2, routes, base: props.base, children: /* @__PURE__ */ jsx2(Routes, { routes, children: props.children }) });
1533
1533
  }
1534
1534
  function Routes(props) {
1535
1535
  const router = useRouter();
1536
1536
  const parentRoute = useRoute();
1537
- const routes = extractRoutes(props.children);
1537
+ const routes = props.routes ?? extractRoutes(props.children);
1538
1538
  const compiledRoutes = routes.map((r) => compileRoute(r));
1539
1539
  const branches = createBranches(compiledRoutes);
1540
1540
  const currentMatches = createMemo(() => {
@@ -1551,11 +1551,14 @@ function Routes(props) {
1551
1551
  const relativePath = locationPath.startsWith(basePath) ? locationPath.slice(basePath.length) || "/" : locationPath;
1552
1552
  return matchRoutes(branches, relativePath) || [];
1553
1553
  });
1554
- const matches = currentMatches();
1555
- return /* @__PURE__ */ jsx2(Fragment2, { children: matches.length > 0 ? renderMatches(matches, 0) : null });
1554
+ return /* @__PURE__ */ jsx2(CurrentMatchesView, { matches: currentMatches });
1556
1555
  }
1557
- function renderMatches(matches, index) {
1558
- const match = matches[index];
1556
+ function CurrentMatchesView(props) {
1557
+ const matches = () => readAccessor(props.matches);
1558
+ return /* @__PURE__ */ jsx2(Fragment2, { children: matches().length > 0 ? renderMatches(matches(), 0) : null });
1559
+ }
1560
+ function RenderMatchesView(props) {
1561
+ const match = props.matches[props.index];
1559
1562
  const route = match.route;
1560
1563
  const router = useRouter();
1561
1564
  const dataState = createSignal3({
@@ -1610,27 +1613,25 @@ function renderMatches(matches, index) {
1610
1613
  match: () => match,
1611
1614
  data: () => dataState().data,
1612
1615
  error: () => dataState().error,
1613
- outlet: () => index + 1 < matches.length ? renderMatches(matches, index + 1) : null,
1616
+ outlet: () => props.index + 1 < props.matches.length ? /* @__PURE__ */ jsx2(RenderMatchesView, { matches: props.matches, index: props.index + 1 }) : null,
1614
1617
  resolvePath: wrapAccessor((to) => {
1615
1618
  const basePath = match.pathname;
1616
1619
  const targetPath = typeof to === "string" ? to : to.pathname || "/";
1617
1620
  return resolvePath(basePath, targetPath);
1618
1621
  })
1619
1622
  };
1620
- let content = /* @__PURE__ */ jsx2(RouteContext.Provider, { value: routeContext, children: renderContent() });
1621
- if (route.errorElement) {
1622
- content = /* @__PURE__ */ jsx2(
1623
- ErrorBoundary,
1624
- {
1625
- fallback: (err, reset) => /* @__PURE__ */ jsx2(RouteErrorContext.Provider, { value: { error: err, reset }, children: route.errorElement }),
1626
- children: content
1627
- }
1628
- );
1629
- }
1630
- if (route.loadingElement) {
1631
- content = /* @__PURE__ */ jsx2(Suspense, { fallback: route.loadingElement, children: content });
1632
- }
1633
- return content;
1623
+ const routeContent = /* @__PURE__ */ jsx2(RouteContext.Provider, { value: routeContext, children: renderContent() });
1624
+ const errorBoundaryContent = route.errorElement ? /* @__PURE__ */ jsx2(
1625
+ ErrorBoundary,
1626
+ {
1627
+ fallback: (err, reset) => /* @__PURE__ */ jsx2(RouteErrorContext.Provider, { value: { error: err, reset }, children: route.errorElement }),
1628
+ children: routeContent
1629
+ }
1630
+ ) : routeContent;
1631
+ return route.loadingElement ? /* @__PURE__ */ jsx2(Suspense, { fallback: route.loadingElement, children: errorBoundaryContent }) : errorBoundaryContent;
1632
+ }
1633
+ function renderMatches(matches, index) {
1634
+ return /* @__PURE__ */ jsx2(RenderMatchesView, { matches, index });
1634
1635
  }
1635
1636
  function Route(_props) {
1636
1637
  return null;