Home / Function/ reroutePayload() — astro Function Reference

reroutePayload() — astro Function Reference

Architecture documentation for the reroutePayload() function in render-context.ts from the astro codebase.

Entity Profile

Dependency Diagram

graph TD
  7f259d51_047e_dff1_1c2a_d2b734d46b09["reroutePayload()"]
  b7425a46_8c1f_1122_7ae3_a00e52db1d90["RenderContext"]
  7f259d51_047e_dff1_1c2a_d2b734d46b09 -->|defined in| b7425a46_8c1f_1122_7ae3_a00e52db1d90
  9c5f11d9_36cd_d739_b7da_42358d602de6["render()"]
  7f259d51_047e_dff1_1c2a_d2b734d46b09 -->|calls| 9c5f11d9_36cd_d739_b7da_42358d602de6
  style 7f259d51_047e_dff1_1c2a_d2b734d46b09 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

packages/astro/src/core/render-context.ts lines 370–426

	async #executeRewrite(reroutePayload: RewritePayload) {
		this.pipeline.logger.debug('router', 'Calling rewrite: ', reroutePayload);
		const oldPathname = this.pathname;
		const { routeData, componentInstance, newUrl, pathname } = await this.pipeline.tryRewrite(
			reroutePayload,
			this.request,
		);
		// This is a case where the user tries to rewrite from a SSR route to a prerendered route (SSG).
		// This case isn't valid because when building for SSR, the prerendered route disappears from the server output because it becomes an HTML file,
		// so Astro can't retrieve it from the emitted manifest.
		// Allow i18n fallback rewrites - if the target route has fallback routes, this is likely an i18n scenario
		const isI18nFallback = routeData.fallbackRoutes && routeData.fallbackRoutes.length > 0;
		if (
			this.pipeline.manifest.serverLike &&
			!this.routeData.prerender &&
			routeData.prerender &&
			!isI18nFallback
		) {
			throw new AstroError({
				...ForbiddenRewrite,
				message: ForbiddenRewrite.message(this.pathname, pathname, routeData.component),
				hint: ForbiddenRewrite.hint(routeData.component),
			});
		}

		this.routeData = routeData;
		if (reroutePayload instanceof Request) {
			this.request = reroutePayload;
		} else {
			this.request = copyRequest(
				newUrl,
				this.request,
				// need to send the flag of the previous routeData
				routeData.prerender,
				this.pipeline.logger,
				this.routeData.route,
			);
		}
		this.url = RenderContext.#createNormalizedUrl(this.request.url);
		const newCookies = new AstroCookies(this.request);
		if (this.cookies) {
			newCookies.merge(this.cookies);
		}
		this.cookies = newCookies;
		this.params = getParams(routeData, pathname);
		this.pathname = pathname;
		this.isRewriting = true;
		// we found a route and a component, we can change the status code to 200
		this.status = 200;
		setOriginPathname(
			this.request,
			oldPathname,
			this.pipeline.manifest.trailingSlash,
			this.pipeline.manifest.buildFormat,
		);
		return await this.render(componentInstance);
	}

Domain

Subdomains

Calls

Frequently Asked Questions

What does reroutePayload() do?
reroutePayload() is a function in the astro codebase, defined in packages/astro/src/core/render-context.ts.
Where is reroutePayload() defined?
reroutePayload() is defined in packages/astro/src/core/render-context.ts at line 370.
What does reroutePayload() call?
reroutePayload() calls 1 function(s): render.

Analyze Your Own Codebase

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

Try Supermodel Free