Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

153
Visualizações
Remove query item from router

I'm using replace in vue to add query to the current url . and i assigned undefined if the value is not there.

this.$router.replace({
  name: "admin-frs",
  query: {
    limit: this.pageSize,
    page: this.currentPage,
    sort: this.sortbyapi || undefined,
    language: this.sortbyapiLang || undefined,
  },
})

this makes the query item disappear from the URL when the query data is getting updated which is fine.

it does not remove it from the query object.

any idea if there's a better approach than this?

plus is it possible to get the query as it is from the route? like &limit=10...etc

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

If I understand correctly, the OP wishes to manipulate the query object passed to router.replace. It can be done with standard js.

Start by explicitly naming a query variable...

let query = $router.query;

To remove something, use js delete operator. For example, to remove query.limit...

// remove the limit
if (!this.pageSize) delete query.limit;

Or, if you're building that query, don't put limit in in the first place...

let query = {};
if (this.pageSize) query.limit = this.pageSize;
if (this.currentPage) query.page = this.currentPage;
// etc for the other properties
// query will now only have props for those selected above

Do any of these manipulations, then pass to the router referring to the variable...

$router.replace({ name: "admin-frs", query }); 

To restate as a string, there are probably several methods, including many in libraries you might have around, but natively...

let params = [];
for (let key in query)
  params.push(`${encodeURIComponent(key)}=${encodeURIComponent(query[key])}`);
const queryString = params.join("&");
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda