Skip to content

Dynamic metadata fails fetch on SSG Components #53036

Answered by hyjoong
nicolasCinzer asked this question in Help
Discussion options

You must be logged in to vote

Use the try{} catch{} statement.

export async function generateMetadata({ params: { name } }: Props): Promise<Metadata> {
   try {
    const [exercise]: Exercise[] = await getExercises({
      name,
      queryType: "equal",
    });
    return {
      title: exercise.name,
      description: `This is the page of ${exercise.name}`,
    };
  } catch (e) {
    return {
      title: "Exercise not Found",
    };
  }
}

Replies: 1 comment 4 replies

Comment options

You must be logged in to vote
4 replies
@nicolasCinzer
Comment options

@hyjoong
Comment options

@hyjoong
Comment options

@nicolasCinzer
Comment options

Answer selected by nicolasCinzer
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Help
Labels
None yet
2 participants