Skip to content

Document getStaticPaths in non-HTML pages #768

@delucis

Description

@delucis

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.)

Metadata

Metadata

Assignees

No one assigned

    Labels

    add new contentDocument something that is not in docs. May require testing, confirmation, or affect other pages.tscguidance required from Technical Steering Committee

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions