Next.js Discord

Discord Forum

Mixed path names

Answered
Northern Shoveler posted this in #help-forum
Open in Discord
Northern ShovelerOP
Is it possible to declare mixed path names such as name-[slug] in Next? Cause I've tried it but it doesn't find me the page I've put in that path.
Answered by American Crow
You could do somth. like
app/blog/[slug]/page.js
export const dynamicParams=false
export async function generateStaticParams() {
  const posts = await fetch('https://.../posts').then((res) => res.json())
 
  return posts.map((post) => ({
    slug: `name-${post.slug}`,
  }))
}
View full answer

7 Replies

American Crow
You could do somth. like
app/blog/[slug]/page.js
export const dynamicParams=false
export async function generateStaticParams() {
  const posts = await fetch('https://.../posts').then((res) => res.json())
 
  return posts.map((post) => ({
    slug: `name-${post.slug}`,
  }))
}
Answer
Komondor
nope
you can do /name/[slug]
but not /name-[slug]
as far as I'm aware
@Komondor as far as I'm aware
Northern ShovelerOP
Okay thank you:blob_wave: