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

210
Visualizações
Direct URI access file serving a vue.js app

I've developed a Vue.js app that uses vue-router to route between components. When routing to a different component, the url changes.

  const routes = [{
    path: "",
    mode: 'history',
    name: "bla",
    component: Bla,
    ...
  },
  {
    path: "/secondpath"
    ...
  }]
  

There is a button on the UI that uses <router-link...> to route to another component which changes path from / to /secondpath. However, when I directly go to .../secondpath on my browser, it returns 404.

If I run the app in dev environment by npm run dev then the above scenario works. If I first build it by vite build and then serve the static files using a web server, e.g. express.js then I get the issue above.

Serving via express.js:

const port = process.env.UI_PORT || 3000
const express = require('express')
const cors = require('cors')
const app = express()

app.use(cors())
app.use(express.static('dist'))
app.listen(port, () => console.log(`Listening on port ${port}`))

I do have only one html file which is the index.html. What do I do wrong here? Should I create multiple html files and somehow redirect user to another html page, instead of using <router-link...>. And how can I do that if that is the issue?

about 4 years ago · Juan Pablo Isaza
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