Angular 17 - 使用deployUrl

问题描述 投票:0回答:1

我有一个关于使用部署 url 配置的问题:https://angular.io/guide/deployment#the-deploy-url

我想我正在混合

baseHref
deployUrl
,如果能得到一些帮助,我将不胜感激。

我实际上正在使用 docker 在 nginx 服务器上部署 Angular 17.3.5 应用程序

我需要我的应用程序路由有一个前缀“/前缀”(

https://localhost/prefix/my-routes
)

首先,我处理这个问题提供了一个像这样的基本href:

{
    provide: APP_BASE_HREF,
    useValue: '/prefix/',
},

但是我发现我的资源和样式设置在我的

angular.json
:

"assets": [
  "src/favicon.ico",
  "src/assets"
],
"styles": [
  "src/styles/styles.scss",
  "src/styles/source/tailwind.css"
],

仍然设置没有前缀:

https://localhost/favicon.ico
例如

当时我尝试在 angular.json 配置中使用deployUrl配置:

"deployUrl": "/prefix/",

但是资源和样式仍然可以在没有前缀的情况下访问:https://localhost/favicon.ico

我似乎遗漏了有关此配置的一些内容,但我没有看到这一点。 先谢谢您的帮助 ! 🙏

angular deployment
1个回答
0
投票

在大多数情况下,您不需要设置deployUrl或APP_BASE_HREF。

您想使用

--base-href yourPrefix

构建您的应用程序

这将在生成的 index.html 文件中添加基本 href。

yourPrefix
将是您所有资源的前缀,这意味着服务器上的文件夹结构也应该是
/yourPrefix/theAssets

© www.soinside.com 2019 - 2024. All rights reserved.