Dynamic pages: Redirect page by code when...

My first time working with dynamic pages here, and I’m not sure how to title this post - so I titled it according to how I think I should approach.

I have a portfolio site with 2 collections: “Clients” and “Projects”. They are related by a reference field in “Projects” that points to the Client that the Project was for.

On the “Client Item” page, I’m displaying all of the Projects that were done for the Client, and when clicked on a Project image, it goes to the “Project Item” page displaying all the information of the Project pulled from the “Projects” collection.

I would like to skip the process of displaying the “Client Item” page when there is only 1 project to its name. How would I do this? The only approach I can think of is by code that looks at the count of projects that are being filtered by the dataset that is filtering the “Projects” based on reference field “Client”, and if that count is less than 2, then somehow go to the dynamic page for that Project without displaying this page. I figured this was the logical approach since there are more than one origins that lead the user to this “Client Item” page.

$w . onReady (() => {
$w ( “#clientProjectsDataset” ). onReady (() => {
let count = $w ( “#clientProjectsDataset” ). getTotalCount ();
// Here goes some kind of code like: If COUNT <2 then go to “PROJECT ITEM” page of current “Project” being displayed through the filtered dataset #clientProjectsDataset
});
});

Attached is a diagram to illustrate what I’m trying to do. I massively lack coding skills so I am at a loss here…