Error message: Wix code SDK error: The url parameter that is passed to the to method cannot be set to the value ....must be of type string

I am trying to create dashboard pages for content management purposes. I have created 2 dashboard pages that are meant to link to each other. However, dashboard pages are not available in the dataset so I am unable to link may pages that way.


So, I am attempting to link through code (which i am a novice - so sorry!). I am receiving the following error message:

Wix code SDK error: The url parameter that is passed to the to method cannot be set to the value /edit-product-detail/13834514. It must be of type string.

Here is my code:

import wixLocation from 'wix-location';

$w.onReady(() => {

    $w("#repeater1").onItemReady(($w, dataItem, index) => {

 //set title to unique product identifier
 let title = dataItem.title;

 //set url link to dynamic dashboard page
 let linkToDynamicPage = ["/edit-product-detail/"+title];

        console.log("dataItem is: ", dataItem);
        console.log("title is: ", title);
        console.log("link to dynamic page is = ", linkToDynamicPage);
 
        $w('#btnEdit').onClick(() => {
            wixLocation.to(linkToDynamicPage);
        });
    });

});//end onReady

I would really appreciate any advice on how to fix my code.

Thanks in advance :slight_smile:

What do you get as result, when doing following console-log?

console.log("link to dynamic page is = ", linkToDynamicPage);
console.log(typeOf linkToDynamicPage);

Surely not a ----> STRING, right?

And this is why you get the message:

Wix code SDK error: The url parameter that is passed to the to method cannot be set to the value /edit-product-detail/13834514. It must be of type string.

Because your defined —> linkToDynamicPage is not a STRING!

You have to convert it first to a STRING, to make it work.

Perhaps this one…

let linkToDynamicPage = [("/edit-product-detail/"+title).toString()]

Thank you so much for your quick response. I didn’t know the typeof function - thank you. It is logging it as an object.

I have changed my code to the code you suggest above

let linkToDynamicPage = [("/edit-product-detail/"+title).toString()]

but I am still receiving the same error message. Any thoughts would be greatly appreciated!

@amy_meyers Ahmad will give us the answer now.
I am not so familiar with “dynamic-links”.

Hi there …

I believe the problem is here:

let linkToDynamicPage = ["/edit-product-detail/"+title];

The problem is that you’re assigning an Array to the link variable, instead of a string, try this instead:

let linkToDynamicPage = `/edit-product-detail/${title}`;

Hope this helps~!
Ahmad

Looks good!

  1. —> this is clear for me
/edit-product-detail/
  1. but —> ${title} <<— never understood this one :grin:
  2. and the additional —>

How to explain that?

That happens, when you never use —> dynamic pages :grin:

Ahmad, that worked! Thank you so much for your help!

@russian-dima I used the template literals to interpolate the variable into the text. It’s pure JavaScript, it has nothing to do with the APIs, or even Wix.

@amy_meyers You’re welcome :wink: Glad that the mystery is solved! Feel free to tag me whenever you need.