notFound() — astro Function Reference
Architecture documentation for the notFound() function in index.ts from the astro codebase.
Entity Profile
Dependency Diagram
graph TD 0c0f77e5_4d7b_ea48_7942_b6cc7bdf6896["notFound()"] e4a1ef92_c598_36b5_dc33_9ab2535360bc["index.ts"] 0c0f77e5_4d7b_ea48_7942_b6cc7bdf6896 -->|defined in| e4a1ef92_c598_36b5_dc33_9ab2535360bc 305c67de_c541_704f_20e8_2d1dc4e1cb92["pathHasLocale()"] 0c0f77e5_4d7b_ea48_7942_b6cc7bdf6896 -->|calls| 305c67de_c541_704f_20e8_2d1dc4e1cb92 style 0c0f77e5_4d7b_ea48_7942_b6cc7bdf6896 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
packages/astro/src/i18n/index.ts lines 328–361
export function notFound({ base, locales, fallback }: MiddlewarePayload) {
return function (context: APIContext, response?: Response): Response | undefined {
if (
response?.headers.get(REROUTE_DIRECTIVE_HEADER) === 'no' &&
typeof fallback === 'undefined'
) {
return response;
}
const url = context.url;
// We return a 404 if:
// - the current path isn't a root. e.g. / or /<base>
// - the URL doesn't contain a locale
const isRoot = url.pathname === base + '/' || url.pathname === base;
if (!(isRoot || pathHasLocale(url.pathname, locales))) {
if (response) {
response.headers.set(REROUTE_DIRECTIVE_HEADER, 'no');
return new Response(response.body, {
status: 404,
headers: response.headers,
});
} else {
return new Response(null, {
status: 404,
headers: {
[REROUTE_DIRECTIVE_HEADER]: 'no',
},
});
}
}
return undefined;
};
}
Domain
Subdomains
Defined In
Calls
Source
Frequently Asked Questions
What does notFound() do?
notFound() is a function in the astro codebase, defined in packages/astro/src/i18n/index.ts.
Where is notFound() defined?
notFound() is defined in packages/astro/src/i18n/index.ts at line 328.
What does notFound() call?
notFound() calls 1 function(s): pathHasLocale.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free