Angular CLI Deploy to Github Pages issue: ERROR Error: Uncaught (in promise): Error: Cannot match any routes

Angular CLI Deploy to Github Pages issue: ERROR Error: Uncaught (in promise): Error: Cannot match any routes

我正在尝试使用此 https://github.com/angular/angular-cli/wiki/stories-github-pages 将我的 Angular SPA 应用程序部署到 github 页面。

我运行这个命令ng build --prod --output-path docs --base-href learningangular

learningangular 是我的 github 存储库的名称。

这是路线

const appRoutes: Routes = [
  { path: "", redirectTo: "/abc", pathMatch: "full" },

  { path: "abc", component: OtherComponent },
  { path: "lazy", loadChildren: "./lazymodule/lazy.module#LazyModule" },

  {
    path: "example",
    loadChildren: "./ExampleModule/example.module#ExampleModule"
  },
  {
    path: "projects",
    component: ProjectsComponent,
    children: [
      {
        path: "",
        component: ErrorPage
      },
      {
        path: ":id",
        component: ProjectDetailsComponent
      }
    ]
  }
];

当我打开 github.io/learningangular 时,它会重新路由到 github.io/learningangular/learningangular/ 并给出错误

ERROR Error: Uncaught (in promise): Error: Cannot match any routes. URL Segment: 'learningangular'
Error: Cannot match any routes. URL Segment: 'learningangular'

我做错了什么?

我正在使用

 "@angular/core": "^5.0.0",
 "@angular/cli": "1.5.0",
 "@angular/compiler-cli": "^5.0.0",

您是 运行 命令 ng build--base-href 的参数错误。它需要以下形式的参数 https://YOUR_GITHUB_USERNAME.github.io/PROJECT_NAME/.

似乎 github wiki 信息在这种情况下并不准确。