C&C Docs
Log in
Pages

Redirects

Any server action can return Response.redirect(url) . From $update on a GET it's a server-side 302 (no body renders); from a $-method over RPC the server replies { redirect } and the client navigates — same API, either entry point.

On GET — $update redirects
// logout.mjs — a pure side-effect + navigate block. $update does the work
// and returns a redirect, so the block renders no body; the browser navigates.
export default {
  async $update() {
    if (this.$auth?.logout) await this.$auth.logout();
    return Response.redirect("/");
  },
};
Result — try it

/logout is that block. Opening it runs $update, which returns a redirect — so you land back home, never seeing a “logout” page.

Open /logout → redirects home
Over RPC — a $-method redirects
// It isn't only $update — ANY $-method can return a redirect. Over RPC the
// server replies { redirect }, and the client navigates (no $update, no merge).
export default {
  $goHome() {
    return Response.redirect("/");
  },
};
Result — click to POST, then navigate

This button calls $goHome on this very block. The method returns a redirect, so instead of merging state back, the client navigates home.