denoland / fresh

The next-gen web framework.
https://fresh.deno.dev
MIT License
12.53k stars 648 forks source link

Custom headers in defineRoute possible? #2339

Closed vicary closed 7 months ago

vicary commented 8 months ago

With defineRoute being a really convenient method for type inference, I almost exclusively use this helper method.

I found it falls short for pages with forms, where it is supposed to go stale when navigated away, a common practise would be adding Cache-Control: no-cache, no-store, must-revalidate.

Is it possible to allow custom headers when returning a component from the helper?

marvinhagemeister commented 7 months ago

Headers are set in so called Handler functions in Fresh that are executed before any rendering happens. See https://fresh.deno.dev/docs/getting-started/custom-handlers

vicary commented 7 months ago

Note to self: useContext breaks (#983) when exporting defineRoute with an async callback, while exporting a sync FunctionComponent works.