When reloading the page (F5 or typing the url into the address bar), the current route is not kept. I have a two separate modules, the main app module and then a dashboard module. These modules each have their own routing modules that they import. If I navigate to 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
Clicking on any links on the pages that use routerlinks work fine.
I am using the latest angular 4 with the latest angular-cli. It worked before the update from angular 2 to angular 4.
Previous version of libraries:
"@angular/core": "^2.3.1",
"@angular/router": "^3.3.1",
Current version of 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"
]
}
}
Turns out I had a call that would hijack the router and redirect to inject parameters. Before the update this.router.url would return the correct url. Now for some reason it always returns root.