Search code examples
vue.jsvue-router

Vue Router return 404 when revisit to the url


I just enable Vue router history mode. And it work fine when I visit to vue routing via v-href or href. But, when I try to refresh that page or go directly from browser address bar, it just return 404. Is there any option to accept refresh/revisit to that url?

The following is my Vue router configuration

var router = new VueRouter({
  hashbang: false,
  history: true,
  mode: 'html5',
  linkActiveClass: "active",
  root:  '/user'
});

Solution

  • By refreshing the page you are making a request to the server with the current url and the server returns 404. You have to handle this on your web framework or web server level.

    This article contains example server configuration: https://v3.router.vuejs.org/guide/essentials/history-mode.html