Redirect and 404 via Response

A loader can throw (or return) a Response to short-circuit the page render. The PRISM runtime detects this and surfaces the Response as the actual HTTP response — same status, headers, and body. This is bext's analogue of Remix's redirect() / notFound().

Tip
You can also return the Response instead of throwing it — the difference is only visible in your TypeScript (throw lets you bail from a nested block without a return). Both paths are equivalent at the runtime level.

Try it

  • Render normally — loader returns { ok: true }.
  • Trigger a 302 — loader throws a Response with status: 302 and a Location header pointing at the server-action-form demo.
  • Trigger a 404 — loader throws a Response with status: 404 and a plain-text body.

The page component doesn't need to know any of this. From its perspective, only the success path renders; the rest is handled before Page() is called.

src/app/examples/redirect-notfound/page.tsxTSX
// src/app/examples/redirect-notfound/page.tsx (loader excerpt)
//
// The PRISM runtime detects a thrown Response and short-circuits the
// page render, forwarding the same status, headers, and body to the
// browser — Remix-style redirect() / notFound().

export async function loader({ request }: LoaderArgs) {
  const url = new URL(request.url);

  if (url.searchParams.get("redirect")) {
    throw new Response(null, {
      status: 302,
      headers: { Location: "/examples/server-action-form" },
    });
  }

  if (url.searchParams.get("missing")) {
    throw new Response("Page not found in our backing store.\n", {
      status: 404,
      headers: { "Content-Type": "text/plain" },
    });
  }

  return { ok: true };
}

export default function Page() {
  return <p>Loaded normally.</p>;
}

Loader output

loader-output.jsonJSON
{
  "ok": true,
  "locale": "en"
}