前端vue3 window.open 项目部署后页面404解决办法
项目场景:
用window.open新开窗口,在本地运行正常,经过部署后页面404
(后端部署不知道是用什么部署的,不清楚,可以生成一个172.0.0.1的服务器,参考代码如下)
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags="-s -w" -o ../buildout/app main.go
upx ../buildout/app
cp config.yaml ../buildout
解决方案:
修改window.open方法
const params = {id: data.id,name: data.name,};const { href } = router.resolve({path: '/xxx', query: {...params}});window.open(href, '_blank');// const queryString = new URLSearchParams(params).toString();// const url = `/xxx?${queryString}`;// window.open(url, "_blank");```
将路由修改成hash路由
import { createRouter, createWebHistory, createWebHashHistory } from 'vue-router'
const router = createRouter({// history: createWebHistory(process.env.BASE_URL),history: createWebHashHistory(process.env.BASE_URL), //这里routes
})
