wixlocation.to() is not working from Mega Menu

I have created a menu using Lightboxex on header with some text, “Dress”, “Jeans” etc. clicking on a text should go to a dynamic page having code to filter the product based on the text value. In my code clicking on a text is not redirecting to the Dynamically created Product page, but staying on the same page the text button is clicked on the Mega Menu or sometimes moving to the Home page. The code I am writing is this -

Code is the Lightbox Menu-
import { session } from ‘wix-storage’ ;
import wixLocation from ‘wix-location’ ;

$w . onReady ( function () {
session . clear ();

$w ( '#text170' ). onClick (( event )=>{ 
    keywrd ( "CollectionID" , "Dress" )  //women dress 

})

$w ( '#text171' ). onClick (( event )=>{ 
    keywrd ( "CollectionID" , "Jeans" ) 

})
});
function keywrd ( collectionid , collectionname ){
wixLocation . to ( “/redirect/” ); //is a blank page
wixLocation . to ( wixLocation . url );
session . setItem ( ‘key1’ , collectionid );
wixLocation . to ( “/products/” ); // Dynamic Product Page
}

I will be grateful if someone helps me to solve this issue. Thanks.

Why do you 4 different redirections one after the other?

Sorry, The exact code is -
function keywrd ( collectionid , collectionname )
{ wixLocation . to ( “/redirect/” ); //is a blank page
session . setItem ( ‘key1’ , collectionid );
wixLocation . to ( “/products/” ); // Dynamic Product Page
}

The reason why I have “{ wixLocation . to ( “/redirect/” ); //is a blank page” and
" wixLocation . to ( “/products/” ); // Dynamic Product Page" is to refresh by redirecting back to the Dynamic Product page from “Redirect” page.

Sorry, its still unclear. If you leave the page to “/redirect” the page code will stop running and should continue to the next redirection (and maybe not even for the setItem 0

@jonatandor35 With my little knowledge I understood that the setItem does not destroy unless session.clear() is used. Am I wrong?

This code is working fine when I am running in unpublished mode, could you please guide me on how to open the dynamic Product page when a text button in Mega Menu created in Lightbox is clicked, especially when the Product page is already open and a text button is clicked to filter the product?

This is the code that runs to filter collection when the product page loads-

$w . onReady ( function () { let x = session . getItem ( ‘key1’ ); //collection id let y = session . getItem ( ‘key2’ ) //product price
filter (x,y)});

function filter ( collection , prodrate ){ if ( collectionName !== collection ) { let newFilter = wixData . filter (); if ( collection ) newFilter = newFilter . hasSome ( ‘collections’ , [ collection ]). and ( newFilter . le ( ‘price’ , prodrate )); await $w ( ’ #dynamicDataset ’ ). setFilter ( newFilter ); collectionName = collection ;}}