nuxt-community / router-module

Nuxt 2 module to use router.js instead of pages/ directory.
MIT License
401 stars 28 forks source link

base route is appended to url on page referesh #103

Open tkeer opened 3 years ago

tkeer commented 3 years ago

With simple latest nuxt app, if you add @nuxtjs/router and set router base to anything, each browser refresh appends base route to the url.

image

package.json

  "name": "my-app",
  "scripts": {
    "dev": "nuxt",
  },
  "dependencies": {
    "nuxt": "^2.15.6"
  },
  "devDependencies": {
    "@nuxtjs/router": "1.6.1"
  }
}

nuxt.config.js

  ssr: false,

  router: {
    base: "/s"
  },

  buildModules: [
    "@nuxtjs/router",
  ],

};

router.js

import Vue from 'vue'
import Router from 'vue-router'

import MyPage from '~/my-page'

Vue.use(Router)

export function createRouter() {
  return new Router({
    mode: 'history',
    routes: [
      {
        path: '/',
        component: MyPage
      }
    ]
  })
}
Lindar90 commented 3 years ago

I can confirm that this issue still exists. @tkeer I found a workaround, you need to use Vue Router's base property instead https://router.vuejs.org/api/#base

// in your router.js file:

const router = new Router({
    mode: 'history',

    base: '/app/',

    routes: [...]
});