S
S
Sergey Nikolaev2019-02-06 12:43:44
Vue.js
Sergey Nikolaev, 2019-02-06 12:43:44

Why does routing stop working on the web server?

I am developing an application on Vue.js . I am using Vue CLI . When starting the server from the console with npm run serve , the routing works. After I build and run the application from the "Open Server" server (because I also use the backend), the routing stops working. That is, when the address bar of the browser says: localhost:8080/about - it works, the About page is loaded. When site.loc/about doesn't work, the browser says: Object not found! The requested URL was not found on this server. The link on the referring page seems to be wrong or outdated. Please inform the author of that page about the error.
I implement routing as standard from the Vue documentation:

//...
const routes = {
  '/': Index,
  '/about': About,
  '/contacts': Contacts
}

new Vue({
  el: '#app',
  data: {
    currentRoute: window.location.pathname
  },
  computed: {
    ViewComponent() {
      return routes[this.currentRoute] || NotFound
    }
  },
  render(h) { return h(this.ViewComponent) }
})

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Sergey Nikolaev, 2019-02-07
@mccrush

Found what I needed. In the documentation for Vue CLI.
See here: https://cli.vuejs.org/ru/guide/deployment.html
and here: https://router.vuejs.org/ru/guide/essentials/histo...
I just didn't know how everyone it is called.

E
Eugene, 2019-02-06
@Elgorm

Open server and node have different configs, the node application probably uses its own server.
this is most likely the reason. You are accessing OpenServer, not the node application.
UPD: I work with nuxt.js, there is a function for generating a static site, if you use it, then it’s quite possible to get by with just one open server

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question