How to pass URL query values to another page?

Hello coders, newbie here!

I have a site that has, lets say two pages:
1 Welcome ( www.example.com/welcome )
2 Auth ( www.example.com/auth )

On the Welcome page, the user gets an option to select whether to Sign Up or Log In to the site. When the user chooses Sign Up , the mode is set to signup and if the user clicks on Log In the mode is set to login.

Now I want to pass this data to the Auth page via the URL for example: www.example.com/auth?mode=login

I know the simplest way to do this would be this:

var mode = login;

wixLocationFrontend.to("/auth?mode=" + mode);

And this is working well.

However I’d like to use the QueryParams add() to achieve the same.

var mode = login;

wixLocationFrontend.queryParams.add({
  "mode": mode
});

And that’s working too… kinda. But here’s the catch. It adds the query parameters to the current page URL (www.example.com/welcome?mode=login) which is completely useless in this case.

So how do I use QueryParams add() along with wixLocationFrontend.to to achieve the following URL: www.example.com/auth?mode=login

(I’m sure there must be a very simple solution to this but me being a beginner can’t figure it out on my own!)

Thanks!

P.S. I’m not using wix-storage-frontend here because my website will have to communicate with external apps in the future so the only way to pass data from the would be through the URL using key - value pairs.

Hi,

Using wixLocationFrontend.to() is the correct way to pass query parameters when navigating between pages.

Since queryParams.add() can only be used once the page is loaded, it does not work for this use case.

Is there some functionality you would like that wixLocationFrontend.to () does not allow you to accomplish?

Thanks for the info!

Currently I’m using wixLocationFrontend.to ( ) and manually adding the queries to the URL instead of using queryParams.add() so it works for now. Thanks! (: