感谢@ochs.tobi 和@funkizer 的帮助。所以是的,base href
该项目不正确。
我要做的第一件事就是将href
in更新index.html
为我的项目名称。
之后,我需要为生产环境重建应用程序,并且只有项目名称为href
:
ng build --prod --base-href "ng-test-deploy"
然后导航到该站点,说 30 秒后,显示了我所追求的。
编辑
在对此进行了更多调查后,我觉得这是一个更好的选择。在里面angular-cli.json
你可以为不同的目的定义不同的应用程序——也许一个用于生产、登台等。像这样:
"apps": [
{
"name": "app-dev",
"root": "src",
"outDir": "dist",
"assets": [
"assets",
"favicon.ico"
],
"index": "index.html",
"main": "main.ts",
"polyfills": "polyfills.ts",
"test": "test.ts",
"tsconfig": "tsconfig.app.json",
"testTsconfig": "tsconfig.spec.json",
"prefix": "app",
"styles": [
"styles.css"
],
"scripts": [],
"environmentSource": "environments/environment.ts",
"environments": {
"dev": "environments/environment.ts",
"prod": "environments/environment.prod.ts"
}
},
{
"name": "app-production",
"baseHref": "/ng-test-deploy",
"root": "src",
"outDir": "dist",
"assets": [
"assets",
"favicon.ico"
],
"index": "index.html",
"main": "main.ts",
"polyfills": "polyfills.ts",
"test": "test.ts",
"tsconfig": "tsconfig.app.json",
"testTsconfig": "tsconfig.spec.json",
"prefix": "app",
"styles": [
"styles.css"
],
"scripts": [],
"environmentSource": "environments/environment.ts",
"environments": {
"dev": "environments/environment.ts",
"prod": "environments/environment.prod.ts"
}
}
],
在这些对象中的每一个中,您都可以看到base-href
任何您喜欢的对象。然后构建它,在本例中是app-production
应用程序,执行以下操作:
ng build --prod --base-href "ng-test-deploy" --app app-production
它将根据其 href 构建用于生产的目标应用程序。省略上面的基本 href 标记会导致与我上面描述的相同的错误,并且是必需的。