routeToState - index name in var

Hi,

I struggle upgrading instantsearch v2 to v4 …

Refering to the doc, routeToState change like this :

// before
routeToState(routeState) {
    return {
      query: routeState.query,
      page: routeState.page,
      // ...
    };
  },
};

// after
routeToState(routeState) {
    return {
      [indexName]: {
        query: routeState.query,
        page: routeState.page,
        // ...
      },
    };
  },

The problem is that now i have to specify the index Name in the returned object attribute .

But i have my index name in a var so i cant write directly the index Name in the js code… i use an object to add it like an attribute.

like so :

 let objectReturn = {};
 objectReturn[index.indexName] = {
         query: routeState.search,
         refinementList: {
                "merchant.name": routeState.merchants,
                "product.application_categories_dict.name": routeState.categories,
                .......
         },
         sortBy: routeState.sort
  };
  console.log(objectReturn);
  return objectReturn;

image

but I end up with the error :

image

My index is formed like this SAND:Channel:... so i think i have to add quotes to my index name.

objectReturn["'"+index.indexName+"'"] = {...}

image

I don’t have error anymore but my refinements are not checked… nothing works !

This drive me crazy.

Please help.

Thanks

In addition to my previous post, it seems that the problem come from refinementList in the returned object.
If i comment this attribut… everything else work just fine (query, sortBy, range, …)

Thanks

Could you please replicate the behavior on this InstantSearch.js sandbox? It will be easier to understand the problem and to get to a solution. Thanks!

I found the solution myself !
I was using a character to split result of refinement in stateToRoute… for example ~.
And of course i forgot to unsplit in routeToState.

Ticket closed