Angular2 Routing: persisting route tabs and child routes
(I posted the problem on SO: http://stackoverflow.com/questions/34925782/angular2-routing-persisting-route-tabs-and-child-routes but decided to ask here, too, hopefully more specific this time) So, basically Router in Angular 2 destroys inactive components (my tabs!). The problem is I don't want this behaviour. Reason is I have some components like charts and data grid and want to switch between them fast, I don't want to recreate them. I've found some workaround for one-level routing but it's totally not a solution. `app.ts`: ``` ts @Component({ /*...*/ }) @RouteConfig([ {path: '/**', redirectTo: ['Dashboard']}, {path: '/dashboard', name: 'Dashboard', component: EmptyRoute}, {path: '/products/...', name: 'Products', component: EmptyRoute}, {path: '/sales', name: 'Sales', component: EmptyRoute}, {path: '/reports', name: 'Reports', component: EmptyRoute}, ]) export class App { constructor(private router: Router) { } public isRouteActive(route) { return this.router.isRouteActive(this.router.generate(route)) } } ``` As you can see `component` is set to `EmptyRoute` (just an empty view `@Component` with no methods and no data) and I don't use `<router-outlet>` but instead I instantiate my route components manually: `app.html`: ``` ts <dashboard [hidden]="!isRouteActive(['/Dashboard'])"></dashboard> <products-management [hidden]="!isRouteActive(['/Products'])"><
Posted by Namek on Jan 22, 2016, 10:52 AM
Tags
Related issues
- 2026 - Microsoft Office 365
- [Ubuntu] `ubuntu-latest` label will use Ubuntu 26.04 in November 2026
- Gamut mapping
- [Codex Desktop] Editing and resending a queued message triggers "App-server queued follow-up no longer exists"
- [Windows] ChatGPT 26.820.60940 fails with "invalid transport in mcp_servers.codex_app"; Beta 26.727.40816 works
- [BUG]: infinite loading of videos
Raise real-world problems, find people facing the same issue, and discuss solutions.5,000 issues0 comments
github (SaaS)
2026 - Microsoft Office 365
[Ubuntu] `ubuntu-latest` label will use Ubuntu 26.04 in November 2026
Gamut mapping
[Codex Desktop] Editing and resending a queued message triggers "App-server queued follow-up no longer exists"
[Windows] ChatGPT 26.820.60940 fails with "invalid transport in mcp_servers.codex_app"; Beta 26.727.40816 works
[BUG]: infinite loading of videos
Restore GPT-5.6 Sol’s 372k Codex context window, or provide an opt-in setting
Codex Desktop for macOS repeatedly triggers `syspolicyd` / `trustd` CPU and memory runaway
Angular2 Routing: persisting route tabs and child routes
(I posted the problem on SO: http://stackoverflow.com/questions/34925782/angular2-routing-persisting-route-tabs-and-child-routes but decided to ask here, too, hopefully more specific this time) So, basically Router in Angular 2 destroys inactive components (my tabs!). The problem is I don't want this behaviour. Reason is I have some components like charts and data grid and want to switch between them fast, I don't want to recreate them. I've found some workaround for one-level routing but it's totally not a solution. `app.ts`: ``` ts @Component({ /*...*/ }) @RouteConfig([ {path: '/**', redirectTo: ['Dashboard']}, {path: '/dashboard', name: 'Dashboard', component: EmptyRoute}, {path: '/products/...', name: 'Products', component: EmptyRoute}, {path: '/sales', name: 'Sales', component: EmptyRoute}, {path: '/reports', name: 'Reports', component: EmptyRoute}, ]) export class App { constructor(private router: Router) { } public isRouteActive(route) { return this.router.isRouteActive(this.router.generate(route)) } } ``` As you can see `component` is set to `EmptyRoute` (just an empty view `@Component` with no methods and no data) and I don't use `<router-outlet>` but instead I instantiate my route components manually: `app.html`: ``` ts <dashboard [hidden]="!isRouteActive(['/Dashboard'])"></dashboard> <products-management [hidden]="!isRouteActive(['/Products'])"><
Comments (0)
No comments yet. Start the discussion.