Home / Function/ getParams() — astro Function Reference

getParams() — astro Function Reference

Architecture documentation for the getParams() function in params-and-props.ts from the astro codebase.

Entity Profile

Dependency Diagram

graph TD
  4ea96ceb_bc51_597e_fd04_d316c65766ef["getParams()"]
  2b2f7826_50bd_a387_80cc_9a3b7ef783f7["params-and-props.ts"]
  4ea96ceb_bc51_597e_fd04_d316c65766ef -->|defined in| 2b2f7826_50bd_a387_80cc_9a3b7ef783f7
  8e1831c9_f4fe_7d1f_bf25_5930ce9a67ef["getProps()"]
  8e1831c9_f4fe_7d1f_bf25_5930ce9a67ef -->|calls| 4ea96ceb_bc51_597e_fd04_d316c65766ef
  style 4ea96ceb_bc51_597e_fd04_d316c65766ef fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

packages/astro/src/core/render/params-and-props.ts lines 86–110

export function getParams(route: RouteData, pathname: string): Params {
	if (!route.params.length) return {};
	// The RegExp pattern expects a decoded string, but the pathname is encoded
	// when the URL contains non-English characters.
	let path = pathname;
	// The path could contain `.html` at the end. We remove it so we can correctly the parameters
	// with the generated keyed parameters.
	if (pathname.endsWith('.html')) {
		path = path.slice(0, -5);
	}

	const paramsMatch =
		route.pattern.exec(path) ||
		route.fallbackRoutes.map((fallbackRoute) => fallbackRoute.pattern.exec(path)).find((x) => x);
	if (!paramsMatch) return {};
	const params: Params = {};
	route.params.forEach((key, i) => {
		if (key.startsWith('...')) {
			params[key.slice(3)] = paramsMatch[i + 1] ? paramsMatch[i + 1] : undefined;
		} else {
			params[key] = paramsMatch[i + 1];
		}
	});
	return params;
}

Domain

Subdomains

Called By

Frequently Asked Questions

What does getParams() do?
getParams() is a function in the astro codebase, defined in packages/astro/src/core/render/params-and-props.ts.
Where is getParams() defined?
getParams() is defined in packages/astro/src/core/render/params-and-props.ts at line 86.
What calls getParams()?
getParams() is called by 1 function(s): getProps.

Analyze Your Own Codebase

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

Try Supermodel Free