Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
935
Dynamic tabs with routing
posted

I am using Angular 11 and latest IG (Dec 2020 release), as I am on a brand new Ignite UI license.

I am unsure how to go about dynamically creating a tab, with a routerlink to another component (with parameter).

Example:

Tab:Scenarios (list of scenarios with header info)

User clicks "Manage" in unbound "Actions" column, should:

  1. Create a tab with scenario.name as tab.title and navigate to /details/<scenario.id>
  2. Scenario List should not reload when navigated back to, unless header info changed in /details
  3. Button to delete /details tab removes from tab bar and navigates user back to most previously active tab

Parents Reply
  • 2680
    Verified Answer
    Offline posted in reply to Chris Sworen
    Hello Chris,

     

    Thank you for following up.

     

     

    To start with, there is a “details” route defined now that uses a path with an id parameter and the newly created tabs point to a DetailsComponent, which can display information about a data item with the corresponding id, extracted from the route parameters. As mentioned, this approach is a standard routing scenario, however, to address the first sub-point of your questions, the exact links, paths, and structures can be defined on application-level. Having said this, the sample also does not aim to replicate any application-specific logic or data models, therefore, as I am not familiar with your custom Classes, the sample cannot account for them. While custom application scenarios can be considered out of the scope of Infragistics developer support, if you would like me to assist you with something specific, I would suggest forking the Stackblitz sample, modifying it with any relevant code, and sending it back to me.

     

    Regarding the tabs not reloading requirement, I understand this use-case and the need to keep the information between switching tabs. For this case, the Angular Route Reuse Strategy comes in the picture. To start with, a BaseRouteReuseStrategy is provided by the framework when the matched router configs are identical. Meaning, if you are switching between tabs with links “details/1” and “details/2” their target component will not be re-initialized. If, however, the switch is between the “/firstPage” and “details/1” – the latter component will be reloaded (you could check this by logging something in the ngOnInit, when switching between different paths).

     

    Fortunately, Angular provides an abstract RouteReuseStrategy class, which can be implemented to provide a way to customize when activated routes get reused. I believe you will find these links on the topic useful as well: Angular Route Reuse Strategy Article, Small Stackblitz demo as provided in this StackOverflow thread.

     

    To further demonstrate such a Custom RouteReuseStrategy, in the modified sample the initial tab’s route is “/firstPage” and the generated tabs’ routes are in the format “details/:id”. The tabs also host some input elements, where you can write and see the input value immediately displayed, as well an IgxGridComponent. As you can observe, if you modify the inputs’ values or some cell in the grid, on tab-switching between the “/firstPage” and “details/:id”  the entered values are not refreshed, meaning the route’s target component’s content has not been re-initialized.

     

    If it comes to preserving some more complicated nested components’ or data structures' state, this would have to be handled on application-level and would be out of the scope of this support case.

     

    Please, test the suggested sample on your side and let me know if I can help with anything else.

     

    Best regards,
    Bozhidara Pachilova
    Associate Software Developer
Children