如果整個單頁應用服務在 /learn/ 下啊鸭,然后 base 就應該設為 “/learn/”
// route.js
const routes = [
{
path: '/',
name: 'Home',
component: Home
},
{
path: '/about',
name: 'About',
// 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/About.vue')
}
]
const router = new VueRouter({
mode: 'history', // history 和 hash 模式 hash模式下路由會多一個“#” history
base: '/learn', // 配置單頁應用的基路徑 localhost:8080/learn/about 和 localhost:8080/about 訪問是一樣的
routes
})
/about
/learn/about