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

120
Visualizações
Update route params when selection changes

In my Vue.js (2.x) app I have a component that represents a mailbox, i.e. displays a list of messages. The component's route is defined thus:

{
  path: '/messages/:messageId',
  name: 'messages',
  component: Messages,

  // this sets the component's messageId prop to the same value as the route param
  props: true
}

When the component is created, the messages are loaded from the server. If the messageId route param is specified, the message with this ID will be selected initially

props: {
  messageId: {
    type: String,
    required: false,
    default: null
  }
},
data () {
  return {
    allMessages: [],
    selectedMessage: null
  }
},
async created () {
  this.allMessages = await messageService.loadMessages()

  if (this.messageId) {
    this.selectedMessage = this.allMessages.find(message => message.id == this.messageId);
  }
}

When the user clicks on a message, selectedMessage is updated. I would also like to update the messageId route param such that the user could (for example)

  • click on a message
  • copy the (updated) URL from the browser's address bar
  • open a new tab and paste the URL to reload the page with the same message selected

However, I'm not sure how to update the route param when the selected message changes? I guess I could do something like

methods: {
  onMessageSelected (selectedMessage) {
    this.selectedMessage = selectedMessage
    const params = { messageId: selectedMessage.id }
    this.$router.push({ name: 'messages', params: params } })
  }
}

But this reloads the whole route/component, causing the list of messages to be fetched again, which is very inefficient. Is there a way to just update the route param in the URL without reloading the route/component?

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

0

I think that you could try:

this.$router.push({ name: 'messages', params: params } })

Or

this.$router.push({ path: `/messages/${messageId}`})
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