# Why not write logic in Astro layouts

> Why you should not put logic in Astro layouts: you cannot call Astro.redirect() there since the response is already sent, so keep that logic in your pages.

Author: Flavio Copes | Published: 2024-03-15 | Canonical: https://flaviocopes.com/why-not-write-logic-in-astro-layouts/

I wrote in [Astro page layout and middleware execution order](https://flaviocopes.com/astro-page-layout-and-middleware-execution-order/) how I moved some logic to a layout.

Had to roll back because turns out I couldn’t run `Astro.redirect()` in a layout, since [Astro](https://flaviocopes.com/astro-introduction/) tells me the response has already been sent to the client.

Turns out this was something I absolutely needed, so moved back to handling the logic in the pages, which was ultimately the right thing from the start.

Discovering new things each and every day.
