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

254
Visualizações
Language as param in Vue Router

I would like to have a language param in my path. For example if there is en before the path, print en.

If I enter http://localhost:8080/en it will give me en but if I enter http://localhost:8080/en/aaaa it will return me undefined how can I get en anyway?

const routes = [
  {
    path: "/:lang?",
    children: [
      {
        path: home,
        component: home
      }
    ]
  }
]
router.beforeEach((to, _, next) => {
  console.log(to.params.lang);
}
about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

Under the assumption that you are planning on adding different language support for your app, I would recommend instead using i18n because it will abstract away things like appending params for different languages.

To your specific question on why you are getting undefined, that could simply be because there is no view page or route for the /aaa route. So Vue is just confused on where you want to go.

about 4 years ago · Juan Pablo Isaza Relatório

0

You can use pure javascript to get the current url and get the parameters through a split.

let myListParams = window.location.href.split('/');
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