@tanstack/solid-router
Version:
Modern and scalable routing for Solid applications
44 lines • 1.59 kB
JSX
import { isNotFound } from '@tanstack/router-core';
import * as Solid from 'solid-js';
import { CatchBoundary } from './CatchBoundary';
import { useRouter } from './useRouter';
// Solid wraps non-Error throws in an Error and stores the original thrown value
// on `cause`, so component-thrown `notFound()` needs one extra unwrapping step.
export function getNotFound(error) {
if (isNotFound(error)) {
return error;
}
if (isNotFound(error?.cause)) {
return error.cause;
}
return undefined;
}
export function CatchNotFound(props) {
const router = useRouter();
// TODO: Some way for the user to programmatically reset the not-found boundary?
const pathname = Solid.createMemo(() => router.stores.location.state.pathname);
const status = Solid.createMemo(() => router.stores.status.state);
return (<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;
}
}}>
{props.children}
</CatchBoundary>);
}
export function DefaultGlobalNotFound() {
return <p>Not Found</p>;
}
//# sourceMappingURL=not-found.jsx.map