#Static pages on a server rendered site
4 messages · Page 1 of 1 (latest)
Hi @tepid oxide. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:
You can mix static and server-rendered routes in the same Astro project, even when output: "server" is set.
1. output: "server" just changes the default
With output: "server", all routes are rendered on demand by default. You can then opt specific routes back into prerendering by exporting prerender = true in those files. [output config; on-demand rendering]
// src/pages/about.astro
---
export const prerender = true;
---
<!-- This page will be built as static HTML even in server mode -->
2. You can still use getStaticPaths() in server mode
getStaticPaths() is specifically for prerendered routes. In server mode, you can still use it, but only on routes that are actually prerendered (i.e. where prerender is true). [getStaticPaths]
// src/pages/posts/[id].astro
---
export const prerender = true; // opt this route into static generation
export async function getStaticPaths() {
return [
{ params: { id: '1' } },
{ params: { id: '2' } },
];
}
const { id } = Astro.params;
---
<h1>{id}</h1>
Those paths will be built to HTML at build time, alongside your server entry output.
3. How this looks in your “mixed” setup
- Your main project is configured with
output: "server". - Any routes you want to “bring in” as static content from the other site:
- Recreate them as pages/endpoints in this project.
- Mark them with
export const prerender = true. - Use
getStaticPaths()if they are dynamic routes and you want multiple static pages. [routing prerender; content collections example]
Astro will then:
- Emit server code for your on-demand routes.
- Emit static HTML (and any related assets) for the prerendered routes, even though the overall output mode is
server.