@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.cjs CHANGED
@@ -1600,13 +1600,13 @@ var import_jsx_runtime2 = require("fict/jsx-runtime");
1600
1600
  function Router(props) {
1601
1601
  const history2 = props.history || createBrowserHistory();
1602
1602
  const routes = extractRoutes(props.children);
1603
- return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(RouterProvider, { history: history2, routes, base: props.base, children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(Routes, { children: props.children }) });
1603
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(RouterProvider, { history: history2, routes, base: props.base, children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(Routes, { routes, children: props.children }) });
1604
1604
  }
1605
1605
  function HashRouter(props) {
1606
1606
  const hashOptions = props.hashType ? { hashType: props.hashType } : void 0;
1607
1607
  const history2 = createHashHistory(hashOptions);
1608
1608
  const routes = extractRoutes(props.children);
1609
- return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(RouterProvider, { history: history2, routes, base: props.base, children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(Routes, { children: props.children }) });
1609
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(RouterProvider, { history: history2, routes, base: props.base, children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(Routes, { routes, children: props.children }) });
1610
1610
  }
1611
1611
  function MemoryRouter(props) {
1612
1612
  const memoryOptions = {};
@@ -1620,17 +1620,17 @@ function MemoryRouter(props) {
1620
1620
  Object.keys(memoryOptions).length > 0 ? memoryOptions : void 0
1621
1621
  );
1622
1622
  const routes = extractRoutes(props.children);
1623
- return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(RouterProvider, { history: history2, routes, base: props.base, children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(Routes, { children: props.children }) });
1623
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(RouterProvider, { history: history2, routes, base: props.base, children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(Routes, { routes, children: props.children }) });
1624
1624
  }
1625
1625
  function StaticRouter(props) {
1626
1626
  const history2 = createStaticHistory(props.url);
1627
1627
  const routes = extractRoutes(props.children);
1628
- return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(RouterProvider, { history: history2, routes, base: props.base, children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(Routes, { children: props.children }) });
1628
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(RouterProvider, { history: history2, routes, base: props.base, children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(Routes, { routes, children: props.children }) });
1629
1629
  }
1630
1630
  function Routes(props) {
1631
1631
  const router = useRouter();
1632
1632
  const parentRoute = useRoute();
1633
- const routes = extractRoutes(props.children);
1633
+ const routes = props.routes ?? extractRoutes(props.children);
1634
1634
  const compiledRoutes = routes.map((r) => compileRoute(r));
1635
1635
  const branches = createBranches(compiledRoutes);
1636
1636
  const currentMatches = (0, import_runtime3.createMemo)(() => {
@@ -1647,11 +1647,14 @@ function Routes(props) {
1647
1647
  const relativePath = locationPath.startsWith(basePath) ? locationPath.slice(basePath.length) || "/" : locationPath;
1648
1648
  return matchRoutes(branches, relativePath) || [];
1649
1649
  });
1650
- const matches = currentMatches();
1651
- return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_jsx_runtime2.Fragment, { children: matches.length > 0 ? renderMatches(matches, 0) : null });
1650
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(CurrentMatchesView, { matches: currentMatches });
1652
1651
  }
1653
- function renderMatches(matches, index) {
1654
- const match = matches[index];
1652
+ function CurrentMatchesView(props) {
1653
+ const matches = () => readAccessor(props.matches);
1654
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_jsx_runtime2.Fragment, { children: matches().length > 0 ? renderMatches(matches(), 0) : null });
1655
+ }
1656
+ function RenderMatchesView(props) {
1657
+ const match = props.matches[props.index];
1655
1658
  const route = match.route;
1656
1659
  const router = useRouter();
1657
1660
  const dataState = (0, import_advanced3.createSignal)({
@@ -1706,27 +1709,25 @@ function renderMatches(matches, index) {
1706
1709
  match: () => match,
1707
1710
  data: () => dataState().data,
1708
1711
  error: () => dataState().error,
1709
- outlet: () => index + 1 < matches.length ? renderMatches(matches, index + 1) : null,
1712
+ outlet: () => props.index + 1 < props.matches.length ? /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(RenderMatchesView, { matches: props.matches, index: props.index + 1 }) : null,
1710
1713
  resolvePath: wrapAccessor((to) => {
1711
1714
  const basePath = match.pathname;
1712
1715
  const targetPath = typeof to === "string" ? to : to.pathname || "/";
1713
1716
  return resolvePath(basePath, targetPath);
1714
1717
  })
1715
1718
  };
1716
- let content = /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(RouteContext.Provider, { value: routeContext, children: renderContent() });
1717
- if (route.errorElement) {
1718
- content = /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
1719
- import_runtime3.ErrorBoundary,
1720
- {
1721
- fallback: (err, reset) => /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(RouteErrorContext.Provider, { value: { error: err, reset }, children: route.errorElement }),
1722
- children: content
1723
- }
1724
- );
1725
- }
1726
- if (route.loadingElement) {
1727
- content = /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_runtime3.Suspense, { fallback: route.loadingElement, children: content });
1728
- }
1729
- return content;
1719
+ const routeContent = /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(RouteContext.Provider, { value: routeContext, children: renderContent() });
1720
+ const errorBoundaryContent = route.errorElement ? /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
1721
+ import_runtime3.ErrorBoundary,
1722
+ {
1723
+ fallback: (err, reset) => /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(RouteErrorContext.Provider, { value: { error: err, reset }, children: route.errorElement }),
1724
+ children: routeContent
1725
+ }
1726
+ ) : routeContent;
1727
+ return route.loadingElement ? /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_runtime3.Suspense, { fallback: route.loadingElement, children: errorBoundaryContent }) : errorBoundaryContent;
1728
+ }
1729
+ function renderMatches(matches, index) {
1730
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(RenderMatchesView, { matches, index });
1730
1731
  }
1731
1732
  function Route(_props) {
1732
1733
  return null;