Botton to dynamic page

I am having trouble getting the export function (onclick()) to link to a dynamic page.

The page that I want the button to link to displays data, which is client-confidential, therefore only the client that is logged in shall have viewing access to it. How do I go about coding this?

Any help will be deeply appreciated.

Thank you.

Hi @mikaelmaingard !

The proper syntax to navigate to a dynamic page would be like this:

wixLocation.to(`/path/${field}`);

Note that the backticks sign is used - instead of the usual apostrophe.
Also - the path being your site path and the field is the field that the dynamic page is divided according to in your site (I’d suggest using the _ID of an item as it’s a unique field) - remember to adjust these parts.

Now, can you please share with me what you tried so far in order to link to a dynamic page?
It would be really helpful for me.

Doron.

2 Likes

Hi Doron!

Thank you so much for your help it is much appreciated!

I have used the following code, which has been successful upon clicking button two:
export function button2_click() {
wixLocation.to(/ClientProfile/Update/${wixUsers.currentUser.id});
}

My issue is that I have another button (button 3), which is meant to link clients to a different dynamic page, displaying their personal data. This is the code I have used:
export function button3_click() {
wixLocation.to(/ClientSummary/${wixUsers.currentUser.id});
}

I am new to Wix and JavaScript, so I am sure it’s a rookie error that you’d be able to fix quite easily.

Hi @mikaelmaingard !

Can you please share a link to your site?
One of us, the Wix Code team, will inspect it and provide you with a solution.
Note that only authorized personnel can gain access to your site.

Doron.

1 Like

Hi Doron!

Your help is so appreciated, thank you. My link is: https://mikaelmaingard.wixsite.com/mvest

Mikael.

Hey @doron-alkalay !

I can imagine you’re a very busy man, so I don’t want to eat up all of your time.

Is there any update regarding my current situation?

Thanks a tonne!

Hi @mikaelmaingard !

When you use as a parameter the wixUsers.currentUser.id - what you actually passing is the ownerID (the ID of the user who created an item in your collection).
What you should do is to query the string value of wixUsers.currentUser.id in the collection and try to retrieve the ID of the item that matches the owner’s.
Take a look a this article that explains the differences between the two.

Doron.

1 Like

Great, thank again @doron-alkalay !