AngularDart: How to change partial parts of layout based on navigation?


Say I have this simple scaffold in my app_component.html:

        <!-- here I have some elements that won't change -->
        <!-- SECTION HEADER: but I want to change this part's content, based on
             navigation or something else (auth roles, for example) -->

    <div class="container">
        <div class="row">
            <div class="col s12">
                <section class="section">
                        <!-- SECTION MAIN: main content goes here -->
<div class="divider"></div>
        some footer here. nothing important

As you can see in the snippet, I’m using a <router-outlet> in SECTION MAIN to show contents which is fine. The problem is, how can I have a changeable part in header section (the SECTION HEADER in the code) and how can I change it’s content based on e.g. navigation, auth roles, etc. ? Does AngularDart support this kind of routing? Thanks in advance.


The short answer is no, the router doesn’t currently have support for doing this easily.

Other frameworks support this functionality through “named” router outlets. This allows multiple outlets to exist in the same view, provided they’re given unique names. Each route configuration then must designate which component is rendered in which named outlet. If this sounds desirable, please feel free to file a feature request:

Of course you could always write your own solution. You could create a component for the header section that dynamically loads a different component, depending on which route is active. It simply needs to inject Router and listen to for route changes.

Answered By – Leon Senft

Answer Checked By – Senaida (FlutterFixes Volunteer)

Leave a Reply

Your email address will not be published. Required fields are marked *