@tanstack/solid-router
Version:
Modern and scalable routing for Solid applications
39 lines (38 loc) • 1.3 kB
JavaScript
import { CatchBoundary } from "./CatchBoundary.js";
import { useRouter } from "./useRouter.js";
import { isNotFound } from "@tanstack/router-core";
import { createComponent, template } from "@solidjs/web";
import * as Solid from "solid-js";
//#region src/not-found.tsx
var _tmpl$ = /* @__PURE__ */ template(`<p>Not Found`);
function getNotFound(error) {
if (isNotFound(error)) return error;
if (isNotFound(error?.cause)) return error.cause;
}
function CatchNotFound(props) {
const router = useRouter();
const pathname = Solid.createMemo(() => router.stores.location.state.pathname);
const status = Solid.createMemo(() => router.stores.status.state);
return createComponent(CatchBoundary, {
getResetKey: () => `not-found-${pathname()}-${status()}`,
onCatch: (error) => {
const notFoundError = getNotFound(error);
if (notFoundError) props.onCatch?.(notFoundError);
else throw error;
},
errorComponent: ({ error }) => {
const notFoundError = getNotFound(error);
if (notFoundError) return props.fallback?.(notFoundError);
else throw error;
},
get children() {
return props.children;
}
});
}
function DefaultGlobalNotFound() {
return _tmpl$();
}
//#endregion
export { CatchNotFound, DefaultGlobalNotFound, getNotFound };
//# sourceMappingURL=not-found.js.map