The following 14 Steps to Create Metadata

Recently delving into Next, I'm perplexed by the inability to set the Id parameter to title.

The id retrieves a string value.

I've ensured my Layout is set up correctly.

//src/app/characters/[id]/page.tsx

import graphqlClient from "@/lib/client";
import GET_CHARACTER from "@/lib/graphql/character";
import { CharacterDetail } from "@/components/characters";
import { notFound } from "next/navigation";
import { Metadata } from "next";

type Props = {
  params: {
    id: string;
  };
};
export async function generateMetaData({ params }: Props): Promise<Metadata> {
  const id = params.id;
  console.log(id);
  return { title: id };
}

const CharacterPage = async ({ params }: Props) => {
  try {
    await generateMetaData({ params });
    const { id } = params;
    const {
      data: { character },
    } = await graphqlClient.query<{ character: Character }>({
      query: GET_CHARACTER,
      variables: { id },
    });
    return (
      <div className="container">
        <CharacterDetail character={character} />
      </div>
    );
  } catch (error) {
    return notFound();
  }
};

export default CharacterPage;

My layout. src/app/layout.tsx

import type { Metadata } from "next";
import { Inter } from "next/font/google";
import "./globals.css";
import React from "react";
import { HeaderLayout, FooterLayout, MainLayout } from "@/components/layout";

const inter = Inter({ subsets: ["latin"] });

export const metadata: Metadata = {
  title: {
    template: "%s | Rick and Morty",
    default: "Rick and Morty",
  },
  description: "Rick and Morty by ortima",
};
interface RootLayoutProps {
  children: React.ReactNode;
}
const RootLayout: React.FC<RootLayoutProps> = ({ children }) => {
  return (
    <html lang="en">
      <body className={inter.className}>
        <HeaderLayout />
        <MainLayout>{children}</MainLayout>
        <FooterLayout />
      </body>
    </html>
  );
};
export default RootLayout;

I attempted to utilize generateStaticParams without success

Answer №1

generateMetaData isn't quite right, better to rename it as generateMetadata

export async function generateMetadata({ params }: Props): Promise<Metadata> {
  const id = params.id;
  console.log(id);
  return { title: id };
}

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

How to Turn Off GridToolbarExport Menu in React Mui DataGrid

Can someone assist me in disabling the menu in GridToolbarExport? This is how my MUI Data Grid is set up: <DataGrid localeText={{ toolbarExport: "Export as CSV", }} disableColumnMenu={true} components={{ Toolbar ...

Initializing variables in Angular2 templates

I am facing an issue where, upon running the application, the console displays all the logs from the ngOnInit function, but the actual view only shows a skeleton without the component variables and text from l18n. It seems like the ngOnInit is not working ...

TS2339 Error: The property does not exist on this particular type when referencing a file relatively

Currently, I am in the process of developing my own UMD library using typescript and webpack. However, I encountered an issue when importing a file that resulted in the error TS2339 (Property 'makeRequest' does not exist on type 'typeof Util ...

Currently, there is a requirement to include past build outcomes in the HTML test report within the playwright

Is there a way to display the previous build status of each test case for every test case? I have been attempting to use test.info() in playwright, but it seems inaccessible from onTestEnd. One option could be to retrieve the previous build data from Jenki ...

Tips for obtaining the width of a child element during a resize event in an Angular application

When resizing the window, I am attempting to determine the width of a specific sub-component. If I want to retrieve the entire app's width, I can use the following code: @HostListener('window:resize', ['$event']) onResize( ...

What is the appropriate way to specify the type of a function parameter to be an express app?

I have a node server running on express and I am looking to add metrics to it during the setup process. Here is a snippet of my code: const app = express(); installMetrics(app); While TypeScript can accurately determine the type of app since I have insta ...

What is the best way to change the data types of all properties in Typescript?

Consider this scenario where an EmployeeDTO type is defined with properties like firstName, lastName, and dateOfBirth using Date type EmployeeDTO = { firstName: string lastName: string; dateOfBirth: Date; } Now, we need a utility type that can trans ...

What is the best approach to incorporating a series of values in TypeScript through an interface?

Trying to incorporate an interface in a class like this: type TLanguage = "TYPE" | "SCRIPT" // Values that can be reused interface AnyInterface { business: TLanguage /** MoreTypes */ } class Anyclass implements AnyInterface{ ...

A step-by-step guide on accessing the data from an uploaded JSON file in a React application

One exciting feature is the drag and drop component that allows users to add multiple files. However, there seems to be an issue with displaying the content of a JSON file once it's added. Below is the code snippet in question: if (files?.length) ...

The 'Observable<ArrayBuffer>' type cannot be assigned to the 'Observable<HttpResponse<User>>' type

Hello there, I am currently facing an issue with setting up an authentication service. Whenever I try to login, I keep getting this error message: Type 'Observable' is not assignable to type 'Observable<HttpResponse>'. Type &a ...

Tips for displaying personalized data with MUI DatePicker

I need to create a React TypeScript component that displays a MUI DatePicker. When a new date is selected, I want a custom component (called <Badge>) to appear in the value field. Previously, I was able to achieve this with MUI Select: return ( ...

Creating a promise instance with the axios create method

As someone who is new to TypeScript, I am learning as I go along. One thing I want to do is create an axios instance that can be reused in my code by passing props only where needed. The framework I'm using is React. // Located in a utils folder // a ...

In Typescript, encountering a member of a union type with an incompatible signature while utilizing the find method on an array of

I need to verify if a specific value exists within an array of objects. The structure of my array is as follows: [ 0: { id: 'unique_obj_id', item: { id: 'unique_item_id', ... }, ... }, 1: {...} ] The objects in the ar ...

Tips for avoiding swiper from interacting with the content upon reaching the final swiper slide button

Can anyone help me with a problem I'm experiencing? When navigating using the next or previous buttons, I always come across one button that is grayed out, indicating that I cannot move forward (for the next button) or backward (for the prev button) a ...

Learning the MEAN stack with Angular 2 - step by step guides

I am eager to master the use of MEAN stacks with Angular 2.0 and TypeScript instead of JavaScript as required. While I have been studying the guides at https://angular.io/guide/quickstart to understand NG2, my challenge lies in integrating all these techno ...

Refining Typescript type with specific error for generics

Seeking assistance to comprehend the situation: TS playground The situation involves a store with an exec method, where narrowing down the type of exec param is crucial for a sub process. However, an error seems to arise due to the store type being generi ...

"Exciting developments in Angular 17 with the introduction of the new @

I need to output elements from an array of strings starting at index 1. arr = [ "str1", "str2", "str3", "str4", "str5" ] The desired output is: str2 str3 str4 str5 To achieve this, use a new @for loop in ...

Incorporate an image icon into an Angular grid

Currently, I am in the process of building a web application using Angular. The main goal is to create a grid and color specific cells based on data input. Below is the snippet of my HTML code: <mat-grid-list cols="10"> <mat-grid-tile * ...

Is there a way to retrieve the value of a particular attribute while hovering the mouse over it?

When I hover my mouse over the innerHTML content, certain words are highlighted with a title attribute value. How can I retrieve the specific title value of the content I am hovering over? This should be done using the mouseover event in the TypeScript fil ...

Retrieve data from a JSON object within an HTML document

How do I display only the value 100 in the following div? <div> {{uploadProgress | async | json}} </div> The current displayed value is: [ { "filename": "Mailman-Linux.jpg", "progress": 100 } ] Here is my .ts file interface: interface IU ...