angular4 路由没有保持刷新

angular4 Routes not being kept on refresh

重新加载页面时(F5 或在地址栏中输入 url),不会保留当前路线。我有两个独立的模块,主应用程序模块和仪表板模块。这些模块每个都有自己导入的路由模块。如果我导航到 http://localhost it redirects to http://localhost/dashboard/overview but if I navigate to any other route though the address bar it redirects back to http://localhost/dashboard/overview

点击使用路由链接的页面上的任何链接都可以正常工作。

我正在使用最新的 angular 4 和最新的 angular-cli。它在从 angular 2 更新到 angular 4.

之前有效

以前版本的库:

"@angular/core": "^2.3.1",
"@angular/router": "^3.3.1",

库的当前版本:

"@angular/core": "^4.0.0",
"@angular/router": "^4.0.0",

应用-routing.module.ts

const routes: Routes = [
  {
    path: '',
    redirectTo: '/dashboard/overview',
    pathMatch: 'full'
  },
  {path: 'logs', component: LogsComponent},
  {path: 'search', component: SearchComponent},
  {path: 'metrics', component: MetricsComponent}
];

@NgModule({
  imports: [RouterModule.forRoot(routes)],
  exports: [RouterModule]
})
export class AppRoutingModule {}

仪表板-routing.module.ts

const dashboardRoutes: Routes = [
  {
    path: 'dashboard',
    component: DashboardComponent,
    children: [
      {path: 'overview', component: OverviewComponent},
      {path: 'partition/:type', component: DashboardPartitionComponent},
      {path: 'latency', component: DashboardLatencyComponent},
    ]
  }
];

@NgModule({
  imports: [ RouterModule.forChild(dashboardRoutes)],
  exports: [ RouterModule ]
})
export class DashboardRoutingModule {}

编辑:

tsconfig.json

{
  "compileOnSave": false,
  "compilerOptions": {
    "outDir": "./dist/out-tsc",
    "baseUrl": "src",
    "sourceMap": true,
    "declaration": false,
    "moduleResolution": "node",
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "target": "es5",
    "typeRoots": [
      "node_modules/@types"
    ],
    "lib": [
      "es2016",
      "dom"
    ]
  }
}

原来我有一个调用会劫持路由器并重定向以注入参数。在更新之前 this.router.url 会 return 正确的 url。现在由于某种原因它总是 return 的根。