How i can rename the attribute name in my URL

ins1

i want to rename category.lvl0 to category in the URL

Thank you!!!

Hi @sandipmahato247!

If you’re using the InstantSearch Router, you can absolutely re-write this part of the URL, you just need to build the URLs manually.

As this guide mentions, setting routing to true is just syntactic sugar. The guide walks you through the underlying code and shows you how to re-write parts of the URL or leave out certain parts of the query entirely.

Hey friend thanks for your time but still I am not able to understand. To be precise I want to rename


this underlined part in the URL and I am still not able to do it, I don’t want lvl.0 stuff inside URL

Can anyone please help me on this

Hey @sandipmahato247 – without seeing your code it’s hard to get more specific about how to help you.

If I start from the assumption that you are using InstantSearch routing (routing: true in your Index configuration) which provides simple URL rewriting to encode query state into your URLs.

It sounds like you want a little more over control over what you gets written into the URLs. which is what is documented in that link I provided.

You’ll need to add two functions to your routing to tell it specifically which parameters you want to encode and decode.

So in your case you’d need those functions to translate back and forth between category.lvl0 and category. This would be something like:

const indexName = 'instant_search';

const search = instantsearch({
  searchClient,
  indexName,
  routing: {
    stateMapping: {
      stateToRoute(uiState) {
        const indexUiState = uiState[indexName];
        return {
          q: indexUiState.query,
          categories: indexUiState..refinementList.category.lvl0
          page: indexUiState.page,
        }
      },
      routeToState(routeState) {
        return {
          [indexName]: {
            query: routeState.q,
            refinementList: {
              categories.lvl0: routeState.categories,
            },
            page: routeState.page,
          },
        };
      },
    },
  },
});

This is just scratch code but hopefully it gives you a path forward.

Hey, man thank you for the response let me try this solution

1 Like