javascript - Angular CLI 部署到 Github 页面问题 : ERROR Error: Uncaught (in promise): Error: Cannot match any routes

标签 javascript angular hosting github-pages static-site

我正在尝试使用此 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 信息似乎并不准确。

关于javascript - Angular CLI 部署到 Github 页面问题 : ERROR Error: Uncaught (in promise): Error: Cannot match any routes,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48436223/

相关文章:

javascript - 在原型(prototype)继承程序中,当在指定对象中找不到属性时

node.js - 在 Angular 4 中使用 Node 模块(网站抓取工具)使用失败

c# - 无法在安全透明方法安全级别问题中执行 CAS 断言

angular - 如何在有 Angular 项目中将GrailsApplicationCommand与Gradle包装器一起使用?

ruby-on-rails - 在 vps 托管上配置 Rails 服务器

asp.net - 如何使用 plesk 面板托管我的 Mvc Web 应用程序?

javascript - 在 JavaScript 中通过引用确定事件处理程序的范围

javascript - VIDEOjs 可拖动进度条

javascript - 鼠标移开后,JQuery 将某些内容返回到原始位置时遇到问题

angular - 将项目从 SystemJS 移动到 Angular CLI/Webpack