Vue CLI 构建 - 使用“/”作为根在本地开发但作为根部署到“/子文件夹/”?
Vue CLI build - develop locally with "/" as root but deploy to "/subfolder/" as root?
我在本地有一个 Vue,主要的 /index.html
是 webroot 但是当我部署时,我希望子文件夹 /stats
成为根目录(并且我的所有路由仍然有效)。
我可以在不手动更改 router/index.js 的情况下执行此操作吗?
vue.config.js
// this doesn't seem to work
module.exports = {
publicPath: process.env.NODE_ENV === "production" ? "/stats/" : "/",
};
router.js
const routes = [
{
path: "/",
name: "HomeView",
component: HomeView,
},
{
path: "/grid",
name: "GridView",
component: GridView,
},
...
]
唯一的建议是确保您设置路由器 base
属性 以匹配您的 publicPath
const router = new VueRouter({
mode: 'history',
base: process.env.BASE_URL, // set the "base" property here
routes
})
我在本地有一个 Vue,主要的 /index.html
是 webroot 但是当我部署时,我希望子文件夹 /stats
成为根目录(并且我的所有路由仍然有效)。
我可以在不手动更改 router/index.js 的情况下执行此操作吗?
vue.config.js
// this doesn't seem to work
module.exports = {
publicPath: process.env.NODE_ENV === "production" ? "/stats/" : "/",
};
router.js
const routes = [
{
path: "/",
name: "HomeView",
component: HomeView,
},
{
path: "/grid",
name: "GridView",
component: GridView,
},
...
]
唯一的建议是确保您设置路由器 base
属性 以匹配您的 publicPath
const router = new VueRouter({
mode: 'history',
base: process.env.BASE_URL, // set the "base" property here
routes
})