Next.js Discord

Discord Forum

Conditional noIndex tag?

Unanswered
Pyr0Lover posted this in #help-forum
Open in Discord
I have a bunch of searchParams used to filter a list of results.

In my sitemap.ts I added all the possible combinations of those searchParams as pages. Since those params, will return different results, and change the filters on the site. I consider them different content and each one should be indexed in google.

Now my question is, what if there are 0 results in the list. Can I add a conditional noIndex tag, like this:

{/* If page returns 0 results, add noIndex tag */}
{params.count === '0' && (
<meta name="robots" content="noindex" />
)}


This feels too easy, is there something I am missing? Once this specific query returns results again, and count is no longer 0, the noIndex should disappear and all go back to indexing smoothly?

The page with 0 results will still be in the sitemap.xml. So only once the crawler enters the page, will it determine if there are 0 results or not. So I feel like this would work perfectly.

0 Replies