Angular 2: Have Child Route Component Replace Parent in router-outlet

前端 未结 5 1657
猫巷女王i
猫巷女王i 2020-12-28 13:21

Is there a way to display a child route in the parent route\'s ?

For example, let\'s say we have two routes:

/users         


        
5条回答
  •  一整个雨季
    2020-12-28 14:00

    If you need to hide something (like a datagrid, or instruction panel) based upon a child route being active you can simply use this:

    Please select a child route!

    It is important to include #outlet="outlet" with the quotes because you're exporting a template variable reference.

    There are also events on router-outlet for activation and deactivation.

    An alternative is to get the child route when the NavigationEnd event occurs, and then make decisions what to show or hide. For simpler cases the first approach should work fine.

    Also not relevant to your question I don't think, but you can completely hide a router-outlet with an *ngIf as you would anything else.

提交回复
热议问题