Next.js Discord

Discord Forum

Add noindex to pages with the ?_rsc param

Unanswered
Japanese jack mackerel posted this in #help-forum
Open in Discord
Japanese jack mackerelOP
I've added a disallow rule in my robots.ts but I'd love to add a noindex too.

I'm a bit confused on how to identify if the page has or not this param, i've tried by doing:

export async function generateMetadata({
  params,
  searchParams
}: {
  params: { handle: string; lang: string; _rsc?: string };
  searchParams: { [key: string]: string | string[] | undefined };
}): Promise<Metadata> {

  return {
    ...extra code
    robots: {
      index: !searchParams._rsc,
      follow: indexable,
      googleBot: {
        index: !searchParams._rsc,
        follow: indexable
      }
    }
  }
}

export default async function MyPage({
  params,
  searchParams
}: {
  params: { handle: string; lang: string; _rsc?: string };
  searchParams: { [key: string]: string | string[] | undefined };
}) {
  ... page code
}


But it's not working 😦

8 Replies

Japanese jack mackerelOP
Up
index:false -> noindex
@Clown https://nextjs.org/docs/app/api-reference/functions/generate-metadata#robots
Japanese jack mackerelOP
Yes ofc, but how do I target only the pages with that search param?
Japanese jack mackerelOP
I mean, if you read the question that's the whole point
If the page has the header you should see it using inspect element/view page source in the head tag?
@Clown If the page has the header you should see it using inspect element/view page source in the head tag?
Japanese jack mackerelOP
I believe there's a misunderstanding.

Currently, when I navigate to a page with _rsc=xxxx, the generateMetadata function does not recognize the parameter, and "searchParams" is an empty object. I have tried to add other search parameters, for example, ?test=123, and searchParams is correctly equal to { test: 123 }.

I cannot identify the presence of the _rsc parameter in the generateMetadata function. The code posted above (as specified at the end) does not work!