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

Mismatch of dynamic route with multiple parameters when one contains hyphens #7265

Closed
1 task done
phortuin opened this issue Jun 1, 2023 · 0 comments · Fixed by #7694
Closed
1 task done

Mismatch of dynamic route with multiple parameters when one contains hyphens #7265

phortuin opened this issue Jun 1, 2023 · 0 comments · Fixed by #7694
Assignees
Labels
- P4: important Violate documented behavior or significantly impacts performance (priority)

Comments

@phortuin
Copy link

phortuin commented Jun 1, 2023

What version of astro are you using?

2.5.6

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

None

What package manager are you using?

npm

What operating system are you using?

MacOS Ventura 13.4

What browser are you using?

Chrome latest

Describe the Bug

For a slug with hyphens: my-first-blog: if I name my page [id]-[slug].astro the dynamic route will be matched. If I name my page [slug]-[id].astro it will not be matched. In that latter version I think Astro matches my- and then expects an id instead of first-blog.

// [id]-[slug].astro
export async function getStaticPaths() {
  const posts = await getCollection("posts");
  return posts.map((post) => ({
    params: { slug: post.slug, id: 1 },
    props: { post },
  }));
}

The above code works perfectly fine. If I change the file name to [slug]-[id].astro, I get a 404 on that route my-first-blog-1 and the Astro CLI will say

A `getStaticPaths()` route pattern was matched, but no matching static path was found for requested path `/my-first-post-1`. Possible dynamic routes being matched: src/pages/[slug]-[id].astro.

I can imagine this is expected behaviour, but there's nothing in the docs or some sort of hint in errors that tells you to set up your route differently (an effective fix is creating the whole slug inside getStaticPaths(): slug: `${post.slug}-${post.id}` but I'd rather go by the book). Thanks!

PS in the stackblitz example, if you rename the route to [slug]-[id].astro you will reproduce this behaviour.

Link to Minimal Reproducible Example

https://stackblitz.com/edit/astro-custom-slugs-smqxwc?file=src%2Fpages%2Findex.astro

Participation

  • I am willing to submit a pull request for this issue.
@bholmesdev bholmesdev added - P4: important Violate documented behavior or significantly impacts performance (priority) content-collections labels Jun 12, 2023
@natemoo-re natemoo-re added feat: content collections Related to the Content Collections feature (scope) and removed content-collections labels Jul 17, 2023
@natemoo-re natemoo-re self-assigned this Jul 17, 2023
@natemoo-re natemoo-re removed the feat: content collections Related to the Content Collections feature (scope) label Jul 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
- P4: important Violate documented behavior or significantly impacts performance (priority)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants