IssueRaiser

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

Raise real-world problems, find people facing the same issue, and discuss solutions.5,000 issues0 comments

github (SaaS)

Angular2 Routing: persisting route tabs and child routes

NamekJan 22, 2016, 10:52 AM

(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.

Comment on this issue