Firebase Hosting根路由如何用nuxtServer替代index.html提供服务?
问题描述
我有一个基于Vue2构建的SPA,正逐步将路由迁移至Nuxt(SSR)+Vue3。通过Firebase Hosting的路由重写配置,已实现将迁移后的路由交由nuxtServer函数处理:
firebase.json配置如下:
"rewrites": [ { "source": "/migrated-route", "function": "nuxtServer" }, ]
我尝试为根路由配置类似规则:
"rewrites": [ { "source": "/", "function": "nuxtServer" }, ]
但该配置不生效——由于dist目录根层级存在index.html,Firebase会直接返回该文件,而非运行nuxtServer。请问如何实现通过nuxtServer提供Nuxt生成的HTML?
解决方案
按照Doug Stevenson的回答,只需简单几步即可解决:
- 将
public/index.html重命名为public/app.html - 在
vue.config.js中添加indexPath: "app.html"(*) - 在
firebase.json中将"**"的重写规则指向/app.html
(*)旧Vue2路由使用Vue CLI3,此配置同样适用于Vite或其他CLI工具
内容的提问来源于stack exchange,提问作者vuelicious
相关产品推荐
相关产品推荐

