StaticPaths Class — astro Architecture
Architecture documentation for the StaticPaths class in static-paths.ts from the astro codebase.
Entity Profile
Dependency Diagram
graph TD 1f9f0fec_a5b7_bce2_94b1_37c4f8b91ea2["StaticPaths"] 90a29f75_7e40_c6ca_4b3f_431e7f4d41c4["static-paths.ts"] 1f9f0fec_a5b7_bce2_94b1_37c4f8b91ea2 -->|defined in| 90a29f75_7e40_c6ca_4b3f_431e7f4d41c4 041e730c_a03b_eb2c_61d6_cb2d05ae599c["constructor()"] 1f9f0fec_a5b7_bce2_94b1_37c4f8b91ea2 -->|method| 041e730c_a03b_eb2c_61d6_cb2d05ae599c b66efb8f_3330_f7b0_10b6_3b7accce9458["getAll()"] 1f9f0fec_a5b7_bce2_94b1_37c4f8b91ea2 -->|method| b66efb8f_3330_f7b0_10b6_3b7accce9458 f2ec0f49_ebee_541a_094a_1ecabd849206["route()"] 1f9f0fec_a5b7_bce2_94b1_37c4f8b91ea2 -->|method| f2ec0f49_ebee_541a_094a_1ecabd849206
Relationship Graph
Source Code
packages/astro/src/runtime/prerender/static-paths.ts lines 24–119
export class StaticPaths {
#app: StaticPathsApp;
constructor(app: StaticPathsApp) {
this.#app = app;
}
/**
* Get all static paths for prerendering with their associated routes.
* This avoids needing to re-match routes later, which can be incorrect due to route priority.
*/
async getAll(): Promise<PathWithRoute[]> {
const allPaths: PathWithRoute[] = [];
const manifest = this.#app.manifest;
// Collect routes to generate (mirrors retrieveRoutesToGenerate)
const routesToGenerate: RouteData[] = [];
for (const { routeData } of manifest.routes) {
// Skip non-prerendered routes
if (!routeData.prerender) continue;
// Include redirects
if (routeIsRedirect(routeData)) {
routesToGenerate.push(routeData);
continue;
}
// Include fallbacks if i18n has fallback configured
if (routeIsFallback(routeData) && manifest.i18n?.fallback) {
routesToGenerate.push(routeData);
continue;
}
// Regular page
routesToGenerate.push(routeData);
}
// Get paths for each route (mirrors getPathsForRoute)
for (const route of routesToGenerate) {
// Also process fallback routes
for (const currentRoute of eachRouteInRouteData(route)) {
const paths = await this.#getPathsForRoute(currentRoute);
allPaths.push(...paths);
}
}
return allPaths;
}
/**
* Get paths for a single route.
* Note: Does not filter duplicates - that's handled by generate.ts with conflict detection.
*/
async #getPathsForRoute(route: RouteData): Promise<PathWithRoute[]> {
const paths: PathWithRoute[] = [];
const manifest = this.#app.manifest;
const routeCache = this.#app.pipeline.routeCache;
// Static route - single pathname
if (route.pathname) {
paths.push({ pathname: route.pathname, route });
return paths;
}
// Dynamic route - need to call getStaticPaths
// Use pipeline.getComponentByRoute which handles redirects and fallbacks
const componentInstance = await this.#app.pipeline.getComponentByRoute(route);
// Determine which route to use for getStaticPaths
const routeToProcess = routeIsRedirect(route)
? route.redirectRoute
: routeIsFallback(route)
? getFallbackRoute(route, manifest.routes)
: route;
const actualRoute = routeToProcess ?? route;
// Use callGetStaticPaths to populate the route cache
const staticPaths = await callGetStaticPaths({
mod: componentInstance,
route: actualRoute,
Domain
Source
Frequently Asked Questions
What is the StaticPaths class?
StaticPaths is a class in the astro codebase, defined in packages/astro/src/runtime/prerender/static-paths.ts.
Where is StaticPaths defined?
StaticPaths is defined in packages/astro/src/runtime/prerender/static-paths.ts at line 24.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free