Fix: Missing Params Property on getStaticPaths Route in Astro

Error message:
Missing params property on `getStaticPaths` route.
Routing & Pages 2025-01-25

What Causes This Error?

This error occurs when an entry returned from getStaticPaths() is missing the required params property. Each entry must have a params object containing values for all dynamic route segments.

The Problem

---
// src/pages/blog/[slug].astro
export function getStaticPaths() {
  return [
    // ❌ Missing params property
    { slug: 'post-1' },
    { slug: 'post-2' },
  ];
}
---
---
export function getStaticPaths() {
  return [
    // ❌ params is null/undefined
    { params: null },
    { params: undefined },
  ];
}
---

The Fix

Add Params Property

---
// src/pages/blog/[slug].astro
export function getStaticPaths() {
  return [
    // ✅ Wrap in params object
    { params: { slug: 'post-1' } },
    { params: { slug: 'post-2' } },
  ];
}
---

With Props

---
export function getStaticPaths() {
  return [
    {
      params: { slug: 'post-1' },
      props: { title: 'First Post' }
    },
    {
      params: { slug: 'post-2' },
      props: { title: 'Second Post' }
    },
  ];
}

const { slug } = Astro.params;
const { title } = Astro.props;
---

Common Scenarios

Mapping Data Incorrectly

---
const posts = [
  { slug: 'post-1', title: 'First' },
  { slug: 'post-2', title: 'Second' },
];

// ❌ Wrong - returns the post object directly
export function getStaticPaths() {
  return posts;
}

// ✅ Correct - wrap in params
export function getStaticPaths() {
  return posts.map((post) => ({
    params: { slug: post.slug },
    props: { title: post.title },
  }));
}
---

Content Collections

---
import { getCollection } from 'astro:content';

export async function getStaticPaths() {
  const entries = await getCollection('blog');

  // ✅ Map to correct structure
  return entries.map((entry) => ({
    params: { slug: entry.slug },
    props: { entry },
  }));
}
---

Multiple Parameters

---
// src/pages/[lang]/blog/[slug].astro
export function getStaticPaths() {
  const posts = ['intro', 'advanced'];
  const langs = ['en', 'es'];

  // ✅ All params must be included
  return langs.flatMap((lang) =>
    posts.map((slug) => ({
      params: { lang, slug },
    }))
  );
}
---

Rest Parameters

---
// src/pages/docs/[...path].astro
export function getStaticPaths() {
  return [
    { params: { path: 'intro' } },
    { params: { path: 'guide/basics' } },
    { params: { path: undefined } }, // ✅ Matches /docs/
  ];
}
---

Quick Checklist

  • Each entry needs { params: { ... } } structure
  • All dynamic segments must be in params
  • Use .map() to transform data arrays
  • Params values must be strings, numbers, or undefined
  • Props are optional but params are required