How to Hide Some Dynamic Item Pages using code

Goal: Hide some dynamic item pages
Background: I want to filter out those pages with code. No-code dataset filters can’t be used as this filter requires coded functions.

Question: I’ve achieved this filter on the dynamic list page. Just need it replicated on its dynamic item pages
Working page code on dynamic list page:

import wixData from 'wix-data';

$w.onReady(async function () { 
    let filter = wixData.filter();
    filter = filter.ne("hide", true); //to filter out items whose 'hide' field is true

    //To filter out based on another function
    const memberIds = await getInactiveOrders();
    filter = filter.not(
        filter.hasSome('_owner', memberIds)
        .and(filter.eq('status', ["Premium"]))
    )
    $w('#listingsDataset').setFilter(filter);  
});
Failed attempts as a noob
// Approach 1) Just replacing the dataset name in the above code  
// Approach 2) Adding the following bit, then setting the filter on the item 
$w.onReady(async function () {
  const dataset = $w('#dynamicDataset');  
  dataset.onReady(async () => {
    let currentItem = dataset.getCurrentItem();
  //filter...
// Approach 3) AI 
$w.onReady(async function () {
  const dataset = $w('#dynamicDataset');  
  dataset.onReady(async () => {
    let currentItem = dataset.getCurrentItem();

    if (currentItem.hide === true) {  
      blockItem();
      return;
    }

    const memberIds = await getInactiveOrders();
    if (memberIds.includes(currentItem._owner) && currentItem.status === "Premium") {
      blockItem();
    }
  });
});

import wixLocation from 'wix-location';
function blockItem() {
  wixLocation.to("/not-available"); // Redirect to a page
}

Working in Wix Editor

Hi,

It would be helpful to add screenshots as it it not so clear what you are trying to filter on the item pages.

Best,
Eitan

Many thanks for your response Eitan. I’ll clarify further here. The goal has always been to redirect entire dynamic item pages

Since the above post, I’ve shifted my approach, as with the previous approach it lands on the page for a while before redirecting. I watched 2 of your vids on the topic & wrote the following code as a noob

Goal: Redirect some dynamic item pages using routers
Background: A single collection’s items whose ‘status’ tag field value equals ‘Premium’ & ‘_owner’ equals ‘1a23’ need to be redirected.
I’m new to routers, checked doc & tutorials, still confused abt how to apply here

Question: For my case, do routers require querying using slugs only? Or can I query using another collection field like

await wixData.query("Properties").eq('status', ["Premium"]).find();

Non working routers.js code: (Not worked even at a basic level. No console.log shows

import wixData from 'wix-data';
import { redirect, next } from 'wix-router';

export async function events_beforeRouter(request) {
	const { path } = request;
	const slug = path[0];
	// Querying collection by slug
	const eventsQueryResult = await wixData.query("Properties").eq("link-properties-title", slug).find();

	const event = eventsQueryResult.items[0];
	console.log("eventlist", event);

    if (event.status[0] === "Premium") {  
		return redirect("/events");
    }
	return next();
}