TanStackT
TanStack9mo ago
7 replies
sad-indigo

cant throw redirects?

idk if this belongs in router questions but i cant throw redirects at all!! it just shows the errors in the console but without doing anything..
import { createFileRoute, redirect } from "@tanstack/react-router";
import { createServerFn } from "@tanstack/react-start";
export const Route = createFileRoute("/test")({
  component: RouteComponent
});

function RouteComponent() {
  return (
    <div>
      <button
        onClick={() => {
          throw redirect({ href: "/client" });
        }}>
        Client Redirect
      </button>
      <button
        onClick={async () => {
          await serverRedirect();
        }}>
        ServerFn Redirect
      </button>
    </div>
  );
}

const serverRedirect = createServerFn().handler(async ctx => {
  throw redirect({ href: "/server" });
});

https://tanstack.com/start/latest/docs/framework/react/server-functions#redirects
image.png
Was this page helpful?