How to exclude some dynamic page from SEO indexing

Hi,

I’ve got a project where we need to index some instance of a dynamic page and some instances need to be hidden.

Basically, if the field " isActive " is false for a given item, it should not be listed and be excluded from SEO indexing. If " isActive " is true , the item should be listed and SEO indexed.

Any idea about how could we achieve that?

From what I read it possible to do that for router-page , but what about dynamic pages?
Maybe some SEO metatag could help?

seo
#DynamicPage

I use this on the routers.js file

export function pageprefix_afterRouter(request, response) {
    let head = {
        "metaTags": 
        [{
          "name": "robots",
          "content": "noindex"
        }]
    };
    response.head = head;
    return response;
}

Then check with this tool: Noindex Tag Test | SEO Site Checkup

For determining which one to index and which one to not you can get the URL path and query against the database object to get the “isActive” value.

For example: If my dynamic page is /prefix/{ID} then I would

wixData.query('collection').eq('_id', id).find()

@Shan thx for you reply,

isn’t “after router” for routers only? how can this works with dynamic page?

@plomteuxquentin I think Router() is for router only. beforeRouter & afterRouter works on dynamic pages too