0

Im using the Router in vue for creating my links to different pages. It works fine and my page is more or less done when I noticed that if I for example opens an URL in a new window it returns as 404 Not Found

I got this code in my Router:

export default new Router({
  mode: "history",
  base: process.env.BASE_URL,
  routes: [
    // navbar
    {
      path: "/",
      name: "home",
      component: () =>
        import(/* webpackChunkName: "home" */ "./views/Home.vue")
    },
    {
      path: "/blog",
      name: "blog",
      // route level code-splitting
      // this generates a separate chunk (about.[hash].js) for this route
      // which is lazy-loaded when the route is visited.
      component: () =>
        import(/* webpackChunkName: "about" */ "./views/Blog.vue")
    },

Say for example I am opening my blog page. The URL will then be mypage.com/blog If I open this in some other page or refresh my page it returns as not found. How can I make it route to the right page on update?

Phil
  • 157,677
  • 23
  • 242
  • 245
acroscene
  • 845
  • 4
  • 16
  • 45
  • 4
    Sounds like you haven't implemented the required server-side URL rewriting to support _history_ mode. See https://router.vuejs.org/guide/essentials/history-mode.html – Phil Mar 24 '19 at 23:26
  • Possible duplicate of [Vue Router return 404 when revisit to the url](https://stackoverflow.com/questions/36399319/vue-router-return-404-when-revisit-to-the-url) – Phil Mar 24 '19 at 23:33
  • Thanks. I did put code from the link in .htaccess which solved it. Another problem is that my navigation doesnt stay on the correct tab. always returns to the default one even though another page is shown. Dont know if there is such a easy fix for that as well? – acroscene Mar 25 '19 at 00:07

0 Answers0