1.路由模式修改
将history模式改为hash模式,并在vue.config.js中将publicPath修改为:'./'
const router = createRouter({
// history: createWebHistory('/'),
history: createWebHashHistory(),
routes
})
//vue.config.js
publicPath: process.env.NODE_ENV === 'production' ? './' : '/'
2.项目部署到nginx
例如访问 http://127.0.0.1/demo时可将打包路径修改为 /demo/
//vue.config.js
publicPath: process.env.NODE_ENV === 'production' ? '/demo/' : '/',