Sections

redirectTo()

redirectTo() stops rendering by throwing MiniFW redirect control flow. The MiniFW route handler catches that value and returns its redirect response. Use it inside a page(), partial(), or layout() when the destination depends on render-time logic.

Render-Time Redirects

import { redirectTo } from "@calvinbonner/minifw/helpers";

if (!session) redirectTo("/login", 303);

The function never returns, so code after it runs only when the condition is false. It defaults to 302; pass another valid redirect status when needed.

const account = page(({ params }) => {
  if (!params["userId"]) redirectTo("/login", 303);

  return "<h1>Account</h1>";
});

Use redirect() when a route always redirects and can be declared directly in mini({ routes }). Use redirectTo() when rendering must first make a decision.

Intentional redirects do not enter Bun's error callback. Use error() for a failure that should be handled there. See isMiniRedirect() when building a custom rendering integration.