0

我有一个 Angular 应用程序,它使用以下配置在端口 4300 上启动:

"scripts": {
  "ng": "ng",
  "start": "ng serve --port 4300 --host 0.0.0.0 --proxy-config proxy.conf.json",
  "build": "ng build",
  "test": "ng test",
  "lint": "ng lint",
  "e2e": "ng e2e"
}

该应用程序可访问以下网址:

http://localhost:4300/#/index.html

我想在上下文根上提供它,例如:“/myApp/”

应用程序必须始终以 开头npm start,我想访问 url:

http://localhost:4300/myApp/#/index.html

我该怎么做?

我尝试的一切都不起作用:

  • 设置<base href="/myApp/">不起作用
  • 设置"build": "ng build --prod --base-href=myApp"不起作用

任何帮助将不胜感激。

4

2 回答 2

1

添加baseHref,deployUrl在您的 angular.json 文件中。添加代码片段:

"serve": {
     "options": {
        "baseHref": "/myApp/",
        "deployUrl": "/myApp/"
      }
    }

<base href="/myApp/">将保持原样。

您可以--base-href=myApp从构建命令中删除

于 2021-10-25T14:43:01.920 回答
0

尝试ng build --prod --base-href /myApp/,或相同但使用ng serve

我认为正斜杠在这里很重要

于 2021-10-25T13:40:23.537 回答