Angular4 Routes not updating on update
When you reload the page (F5 or enter a URL in the address bar), the current route is not saved. I have two separate modules, the main application module and then the panel module. These modules have their own routing modules that they import. If I go to http: // localhost it redirects to http: // localhost / dashboard / overview , but if I go to any other route even though the address bar redirects it back to http: // localhost / dashboard / overview
Clicking on any links on the pages where the routers are running works fine.
I am using latest angular 4 with latest angular-cli. It worked before upgrading from angular 2 to angular 4.
Previous version of the libraries:
"@angular/core": "^2.3.1",
"@angular/router": "^3.3.1",
Current version of the libraries:
"@angular/core": "^4.0.0",
"@angular/router": "^4.0.0",
app-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 {}
dashboard-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 {}
EDIT:
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"
]
}
}
source to share