ng build命令运行“找不到条目”后发生错误

时间:2018-08-09 22:42:22

标签: angular npm angular-cli

我使用命令“ ng build --prod”或“ ng build --prod --base-href ./”构建项目,并且在Web服务器上也可以正常运行项目,但也可以,但是当我按F5键时,我可以接收到下一个错误 enter image description here

我有角度cli版本 enter image description here

和我的package.json

{
  "name": "ConceptPeluqueria",
  "version": "1.0.0",
  "license": "ConceptPeluqeria",
  "scripts": {
    "ng": "ng",
    "start": "ng serve",
    "maxbuild": "ng build --prod",
    "build": "ng build --prod --base-href ./",
    "gitbuild": "ng build --prod --base-href /start-angular/SB-Admin-BS4-Angular-6/master/dist/",
    "test": "ng test",
    "test-ci": "TEST_CI=true ng test",
    "lint": "ng lint",
    "subirtodo": "git add . & git commit -m \"Commit automatico\" & git push origin master",
    "e2e": "ng e2e"
  },
  "private": true,
  "dependencies": {
    "@angular/animations": "^6.0.0",
    "@angular/common": "^6.0.0",
    "@angular/compiler": "^6.0.0",
    "@angular/core": "^6.0.0",
    "@angular/forms": "^6.0.0",
    "@angular/http": "^6.0.0",
    "@angular/platform-browser": "^6.0.0",
    "@angular/platform-browser-dynamic": "^6.0.0",
    "@angular/router": "^6.0.0",
    "@ng-bootstrap/ng-bootstrap": "^2.2.2",
    "@ngx-translate/core": "^10.0.1",
    "@ngx-translate/http-loader": "^3.0.1",
    "chart.js": "^2.7.2",
    "core-js": "^2.5.5",
    "font-awesome": "^4.7.0",
    "ng2-charts": "^1.6.0",
    "rxjs": "^6.1.0",
    "yarn": "^1.6.0",
    "zone.js": "^0.8.26"
  },
  "devDependencies": {
    "@angular/cli": "6.1.2",
    "@angular/compiler-cli": "^6.0.0",
    "@angular/language-service": "^6.0.0",
    "@types/jasmine": "~2.8.6",
    "@types/jasminewd2": "~2.0.3",
    "@types/node": "^9.6.1",
    "codelyzer": "~4.2.1",
    "jasmine-core": "~3.1.0",
    "jasmine-spec-reporter": "~4.2.1",
    "karma": "~2.0.0",
    "karma-chrome-launcher": "~2.2.0",
    "karma-cli": "~1.0.1",
    "karma-coverage-istanbul-reporter": "^1.4.2",
    "karma-jasmine": "~1.1.1",
    "karma-jasmine-html-reporter": "^1.0.0",
    "protractor": "~5.3.0",
    "ts-node": "~5.0.1",
    "tslint": "~5.9.1",
    "typescript": "~2.7.0",
    "@angular-devkit/build-angular": "~0.6.0"
  }
}

任何帮助将不胜感激

1 个答案:

答案 0 :(得分:0)

这是刚开始托管单页应用程序(SPA)的人们的常见问题。问题是整个Angular应用程序都从一条路由运行,在您的情况下127.0.0.1:8887/,Angular应用程序中存在的所有路由(即/dashboard)都不是服务器知道的路由。这就是为什么如果您在根目录下输入,则整个应用程序都可以正常运行,但是如果您转到类似127.0.0.1:8887/dashboard的子路由,则该路由将失败,因为Web服务器没有与该路由绑定的任何信息。

长话短说,您需要使用一台服务器,当它收到任何404路由错误时,应为index.html文件提供服务。如果您在Google搜索“如何提供SPA应用程序”中搜索,则有很多选择,您自己的服务器甚至可以使用。