Vue路由器-如何在生产中的新选项卡中打开



我正在使用Vue、Vuetify,我的数据库位于postgreSQL中,带有来自postgREST的API后端(https://postgrest.org/en/stable/)。当使用localhost和hash模式时,本地一切都很好。当使用以下语法时,我可以在新的选项卡中打开组件产品:

const route = this.$router.resolve({ path: `/product/${value.id}` }) (1)
window.open(route.href, '_blank')                                    (2)

然而,在使用postgREST服务器的生产环境中,当在新选项卡中打开时,我得到了错误的url:

http:server_name/api/#/product/1                                     (3)

当我从上面的url(3(中删除/api并像这样重写时:

http:server_name/#/product                                           (4)

我得到了正确的页面
是否可以编写nginx规则来确保http://server_name/api/#/product/1是否自动重写为正确的urlhttp:server_name/#/project?或者我如何更改vue-router或vue-config文件,以便在生产中获得与locahost中相同的行为?

一个可能的客户端解决方案是在生产模式中去掉/api前缀:

const url = process.env.NODE_ENV === 'production'
? route.href.replace('/api', '')
: route.href
window.open(url, '_blank')

相关内容