-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Document getStaticPaths in non-HTML pages #768
Copy link
Copy link
Closed
Labels
add new contentDocument something that is not in docs. May require testing, confirmation, or affect other pages.Document something that is not in docs. May require testing, confirmation, or affect other pages.tscguidance required from Technical Steering Committeeguidance required from Technical Steering Committee
Description
Non-HTML pages support exporting a getStaticPaths function just like .astro dynamic routes do, but we don’t currently document it. This should at least be mentioned in the non-HTML section of the Pages guide and probably deserves a comment in the getStaticPaths reference and Dynamic routes docs.
Particular gotcha to mention:
If the file route is src/pages/[api].json.ts, the api param returned by getStaticPaths need to include .json. Not sure if that’s intended or a bug — we should check with core. Here’s an example:
import type { APIRoute } from 'astro';
export const get: APIRoute = async ({ params }}) => {
return {
body: JSON.stringify({
path: params.api,
}),
};
};
export function getStaticPaths() {
return [
{ params: { api: 'a.json' } }, // ✅ works => outputs '/a.json'
{ params: { api: 'b' } }, // ❌ breaks => outputs '/b'
];
}(I guess under the hood this is essentially working as if the .json part of the filename is not there.)
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
add new contentDocument something that is not in docs. May require testing, confirmation, or affect other pages.Document something that is not in docs. May require testing, confirmation, or affect other pages.tscguidance required from Technical Steering Committeeguidance required from Technical Steering Committee