Angular 6在Firebase托管中部署的多个应用程序

3
我有一个具有多个项目的Angular 6应用程序,我将重写规则配置为以下内容:
"rewrites": [
  {
    "source": "/ticket/**",
    "destination": "/ticket-app/index.html"
  },
  {
    "source": "/client/**",
    "destination": "/client-app/index.html"
  },
  {
    "source": "/admin/**",
    "destination": "/admin-app/index.html"
  }
],

应用程序已经部署成功,但当访问URL时,应用程序无法正常运行,浏览器中的.js文件没有加载。当您访问.js文件的URL时,只能获取.html页面。我可以在开发者控制台中看到以下错误:Chrome consoleChrome console 所有对.js文件和.css文件的请求都始终返回index.html页面,我尝试了其他重写格式,例如:
"rewrites": [
  {
    "source": "/ticket/**",
    "destination": "/ticket-app/**"
  },
  {
    "source": "/client/**",
    "destination": "/client-app/"
  },
  {
    "source": "/admin/**",
    "destination": "/admin-app/*"
  }
],

但是没有起作用。我使用以下命令构建了应用程序:
ng build ticket-app --prod --base-href '/ticket/'

thanks

1个回答

0

您还需要添加deployUrl。有两个选项

1)在构建应用程序时添加--deploy-url参数

ng build ticket-app --prod --base-href '/ticket/' 

2) 在每个应用程序的angular.json中添加配置

"build": {
          "options": {
            ...
            "baseHref": "/ticket/",
            "deployUrl": "/ticket/"
          },
 ...
}

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接