我想知道是否可以将基本href配置为tomcat或应用程序服务器的环境变量。
例如:
index.html
<base href="/${environment.tomcat}/">
还是操作系统的环境变量?
答案 0 :(得分:0)
environment.ts
export const environment = {
production: false,
tomcat: '/'
};
environment.prod.ts
export const environment = {
production: true,
tomcat: '/my-app/'
};
在您的应用模块中:〜
import { Component, NgModule } from '@angular/core';
import { APP_BASE_HREF } from '@angular/common';
import { environment } from '../environments/environment';
@NgModule({
providers: [{provide: APP_BASE_HREF, useValue: environment.tomcat}]
})
class AppModule {}
OR
使用Angular CLI内置功能:〜
# Sets base tag href to /myUrl/ in your index.html
ng build --base-href /myUrl/
ng build -bh /myUrl/
您可以在package.json
中更新脚本:〜
"scripts": {
//...
"start": "ng serve -bh /anotherUrl/",
"build": "ng build -bh /tomcatServerURL/",
//..
},
希望这会有所帮助!