nginx错误'无法匹配任何路由'使用Angular 2路由器3.0.0.-alpha.7

时间:2016-06-30 01:49:32

标签: nginx angular router

nginx似乎不适用于Angular 2 RC3路由器的prod版本。我收到以下错误:

Error: Uncaught (in promise): Error: Cannot match any routes: ''
at s (zone.js:538)
at zone.js:515
at t.invoke (zone.js:323)
at Object.onInvoke (ng_zone_impl.js:46)
at t.invoke (zone.js:322)
at t.run (zone.js:216)
at zone.js:571
at t.invokeTask (zone.js:356)
at Object.onInvokeTask (ng_zone_impl.js:37)
at t.invokeTask (zone.js:355)

我的nginx配置非常简单:

    listen       8080;
    server_name  localhost;
    charset utf-8;
    location / {
        root   /Users/JARVIS/src/web/ui/dist;
        index  index.html index.htm;
    }

我无法判断它是如何配置的,也不是新路由器或其编译方式的问题。我正在使用angular2-webpack-starter。此问题仅发生在nginx中托管的prod版本中。在开发服务器中,一切正常。

我的路线很直接:

export const ChromeRoutes: RouterConfig = [
  {
    path: '',
    component: Chrome,
    canActivate: [AuthGuard], // this protects all child routes
    children: [
      { path: 'dashboards', component: Dashboards },
      { path: 'inventory',  component: Inventory },
      { path: 'content',    component: Content },
      { path: 'settings',   component: Settings },
      { path: '',           redirectTo: '[/dashboards]' }
    ]
  }

我试过改变''到' chrome'没有变化。有或没有redirectTo条目都没关系。

编辑: 我通过JSON.stringify()完整路由定义... javascript [{ "path": "login", "terminal": true }, { "path": "", "canActivate": [null], "children": [{ "path": "dashboards" }, { "path": "inventory" }, { "path": "content" }, { "path": "settings" }] }, { "path": "inventory", "canActivate": [null], "children": [{ "path": "", "terminal": true }, { "path": ":id" }] }]

1 个答案:

答案 0 :(得分:1)

  • 如果<base href=".">中有<head>,请尝试将其更改为<base href="/">

  • 添加terminal: true空路径

{ path: '',           redirectTo: '[/dashboards]': pathMatch: 'full' }

&lt; = RC.3

{ path: '',           redirectTo: '[/dashboards]': terminal: true }