How to switch to a Dynamic Page via code?

I need to switch to a second page on a website, when pressing a button. Unfortunately, the static linking in the button configuration won’t work, because the page is a Dynamic Page.

The button is on the Home Page. When I press the button, it runs a database filtering and it harvests the data to be displayed on my dynamic page, but after the page content has been generated, i want to automatically switch to it. I could’t figure out how to do it.

I can generate the dynamic link from the filtering function attached to the button action (i have the url + prefix), but I don’t know what to do from there.

Any help appreciated.

Use wixLocation.to