Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Static APIRoutes can't receive props from getStaticPaths #4920

Closed
1 task
Jutanium opened this issue Sep 29, 2022 · 0 comments · Fixed by #4986
Closed
1 task

Static APIRoutes can't receive props from getStaticPaths #4920

Jutanium opened this issue Sep 29, 2022 · 0 comments · Fixed by #4986
Labels
- P2: nice to have Not breaking anything but nice to have (priority)

Comments

@Jutanium
Copy link
Contributor

What version of astro are you using?

1.3.0

Are you using an SSR adapter? If so, which one?

None

What package manager are you using?

pnpm

What operating system are you using?

Mac

Describe the Bug

Custom endpoints/API Routes support getStaticPaths for dynamic routing in static mode. The params in each route can be accessed using the params property of APIContext, but there is no way to access the props returned from getStaticPaths.

The fix would expose props on APIContext.

// src/pages/[id].json.ts

import type { APIRoute } from 'astro';

export const get: APIRoute = async ({ params, request, props }) => {
  const id = params.id;
  console.log(props); //undefined
  return ...
};

export function getStaticPaths() {
  return [
    { params: { id: '0' }, props: { name: 'Sarah' } },
    { params: { id: '1' }, props: { name: 'Chris' } },
    { params: { id: '2' }, props: { name: 'Fuzzy' } },
  ];
}

Link to Minimal Reproducible Example

https://stackblitz.com/edit/github-e6xf7j?file=src%2Fpages%2F[id].json.ts%3AL8&on=stackblitz

Participation

  • I am willing to submit a pull request for this issue.
@matthewp matthewp added the - P2: nice to have Not breaking anything but nice to have (priority) label Sep 30, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
- P2: nice to have Not breaking anything but nice to have (priority)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants