Next.js Discord

Discord Forum

Dynamic Metadata

Unanswered
limxuan posted this in #help-forum
Open in Discord
Avatar
limxuanOP
AIM:
1. creating a website with dynamic metadata titles depending on the endpoint of the url
2. redirect users that click on the link to the main page without the main page's metadata interfering the dynamic path's metadata

ISSUE: Its showing the redirected page's metadata instead of the dynamic path's metadata, i guess its something to do with the redirect

// app/[endpoint]/page.tsx
import { wait } from "@/utils/globalFunction";
import { redirect } from "next/navigation";

type Props = {
    params: { endpoint: string };
    searchParams: { [key: string]: string | string[] | undefined };
};

const Component = async () => {
    await wait(5000);
    redirect("/");
};

export const generateMetadata = (props: Props) => {
    return {
        title: props.params.endpoint
    };
};

export default Component;


// for fetch testing
// app/fetch/page.tsx
"use client";

const FetchPage = async () => {
    const response = await fetch("http://localhost:3000/test");
    const resText = response.text();

    return <div>{resText}</div>;
};

export default FetchPage;

14 Replies

Avatar
limxuanOP
anyone? :*(
Avatar
Broad-snouted Caiman
Why u waiting for generating meta data
Avatar
limxuanOP
am i? i thought i was waiting for the redirect
cuz whenever i fetch it just gives me the homepage’s metadata
Avatar
Broad-snouted Caiman
can u show result of fetch testng
Avatar
limxuanOP
1st picture: redirect("/") is commented out
2nd picture: redirect("/") is not commented
Image
Image
Avatar
limxuanOP
b
tldr i just want to let the users to fetch the route's html but when they click on it i want to redirect to home page
Avatar
limxuanOP
b
Avatar
Asiatic Lion
i dont know if this is possible, with the way nextjs does static generation at least
i have a similar issue, where i have a protected page with metadata but it only shows the login page metadata as I redirect to that if the user isnt logged in, and so far i havent seen a solution
hell, even google has that issue
A possible solution would be instead of doing a redirect, show a page with only one button that says "go home" or something, i dont know if what youre tryna do is possible due to how crawlers work
Avatar
limxuanOP
i appreciate your reply very much sectonic its a bummer