There seems to be another (rather hacky) way to reuse the router-outlet in one template. This answer is intendend for informational purposes only and the techniques used here should probably not be used in production.
https://stackblitz.com/edit/router-outlet-twice-with-events
The router-outlet is wrapped by an ng-template. The template is updated by listening to events of the router. On every event the template is swapped and re-swapped with an empty placeholder. Without this "swapping" the template would not be updated.
This most definetly is not a recommended approach though, since the whole swapping of two templates seems a bit hacky.
in the controller:
ngOnInit() {
this.router.events.subscribe((routerEvent: Event) => {
console.log(routerEvent);
this.myTemplateRef = this.trigger;
setTimeout(() => {
this.myTemplateRef = this.template;
}, 0);
});
}
in the template:
<div class="would-be-visible-on-mobile-only">
This would be the mobile-layout with a router-outlet (inside a template):
<br>
<ng-container *ngTemplateOutlet="myTemplateRef"></ng-container>
</div>
<hr>
<div class="would-be-visible-on-desktop-only">
This would be the desktop-layout with a router-outlet (inside a template):
<br>
<ng-container *ngTemplateOutlet="myTemplateRef"></ng-container>
</div>
<ng-template #template>
<br>
This is my counter: {{counter}}
inside the template, the router-outlet should follow
<router-outlet>
</router-outlet>
</ng-template>
<ng-template #trigger>
template to trigger changes...
</ng-template>