Home / Function/ route() — astro Function Reference

route() — astro Function Reference

Architecture documentation for the route() function in static-paths.ts from the astro codebase.

Entity Profile

Dependency Diagram

graph TD
  f2ec0f49_ebee_541a_094a_1ecabd849206["route()"]
  1f9f0fec_a5b7_bce2_94b1_37c4f8b91ea2["StaticPaths"]
  f2ec0f49_ebee_541a_094a_1ecabd849206 -->|defined in| 1f9f0fec_a5b7_bce2_94b1_37c4f8b91ea2
  b66efb8f_3330_f7b0_10b6_3b7accce9458["getAll()"]
  b66efb8f_3330_f7b0_10b6_3b7accce9458 -->|calls| f2ec0f49_ebee_541a_094a_1ecabd849206
  style f2ec0f49_ebee_541a_094a_1ecabd849206 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

packages/astro/src/runtime/prerender/static-paths.ts lines 77–118

	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,
			routeCache,
			ssr: manifest.serverLike,
			base: manifest.base,
			trailingSlash: manifest.trailingSlash,
		});

		// Convert params to pathnames using stringifyParams
		for (const staticPath of staticPaths) {
			const pathname = stringifyParams(staticPath.params, route, manifest.trailingSlash);
			paths.push({ pathname, route });
		}

		return paths;
	}

Domain

Subdomains

Called By

Frequently Asked Questions

What does route() do?
route() is a function in the astro codebase, defined in packages/astro/src/runtime/prerender/static-paths.ts.
Where is route() defined?
route() is defined in packages/astro/src/runtime/prerender/static-paths.ts at line 77.
What calls route()?
route() is called by 1 function(s): getAll.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free