Re-routing a page to another

I have a page that in some conditions has to be automatically rerouted to another page.
2 pages, page1 and page2
when the user call page1, when some condition are met (ie when some parameters are present in the url adress), the page1 should not be seen and page2 is displayed.
I tried coding this in the $w.onReady(function (): within an if condition checking the parameters, set some command to open page2
for this opening I tested

  • a direct command with [wixLocation.to(‘"full](wixLocation.to(’"full) URL…/page2’);
  • put a button woth the link to page2 and simulate a click button event with $w ( “#buttonPage1” ). click (); as documented somewhere, but seems to be a wrong syntax

any idea on that