vue路由使用history模式。
打包后用http-server本地跑
直接访问localhost:8080 可以访问首页
访问localhost:8080/A 页面404
网上找的答案基本是配置服务器的重写规则,如果要用http-server在本地跑,该怎么配置才能运行起来
vue路由使用history模式。
打包后用http-server本地跑
直接访问localhost:8080 可以访问首页
访问localhost:8080/A 页面404
网上找的答案基本是配置服务器的重写规则,如果要用http-server在本地跑,该怎么配置才能运行起来
如果是vue-cli 的项目 在根目录添加vue.config.js 配置文件 添加根路径配置 即可打包部署在任意环境 ,如果有接口还得配置反向代理
module.exports = {
// 基本路径
publicPath:"./", // 可以设置成相对路径,这样所有的资源都会被链接为相对路径,打出来的包可以被部署在任意路径
outputDir:"dist", //打包时生成的生产环境构建文件的目录
assetsDir: 'public', // 放置生成的静态资源 (js、css、img、fonts) 的 (相对于 outputDir 的) 目录
devServer: {
proxy: {
'/api' : {
target : 'http://localhost:8002/dev',
changeOrigin: true,
ws: true,
pathRewrite: {
'^/api': '',
},
},
}
}
}
}