You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.14 12:27:34