@fictjs/router 0.16.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 +25 -24
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +25 -24
- package/dist/index.js.map +1 -1
- package/package.json +5 -5
- package/src/components.tsx +50 -32
package/dist/index.d.cts
CHANGED
package/dist/index.d.ts
CHANGED
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
|
-
|
|
1555
|
-
return /* @__PURE__ */ jsx2(Fragment2, { children: matches.length > 0 ? renderMatches(matches, 0) : null });
|
|
1554
|
+
return /* @__PURE__ */ jsx2(CurrentMatchesView, { matches: currentMatches });
|
|
1556
1555
|
}
|
|
1557
|
-
function
|
|
1558
|
-
const
|
|
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 ?
|
|
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
|
-
|
|
1621
|
-
|
|
1622
|
-
|
|
1623
|
-
|
|
1624
|
-
{
|
|
1625
|
-
|
|
1626
|
-
|
|
1627
|
-
|
|
1628
|
-
|
|
1629
|
-
|
|
1630
|
-
|
|
1631
|
-
|
|
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;
|