To start: my StackBlitz contains the exact case I'm trying to solve.
Like the title says I have a routed dialog (dialog that opens based on the route) and inside this dialog I want to have a tab control. Every tab should also be bound to a route, so I think my dialog should somehow also get a <router-outlet/>
But when I add this extra <router-outlet/>
without the name argument the rendering (I think) goes frenzy -> result: unresponsive app.
When I add the name argument and I also configure the routing it doesn't work either.
const routes: Routes = [
{path: '', redirectTo: '/home', pathMatch: 'full'},
{path: 'home', component: HomeComponent, children: [
{path: 'dialog', component: DialogWrapperComponent},
{path: 'routed-dialog',
children: [
{path: '', component: RoutedDialogWrapperComponent},
{path: 'first', component: FirstComponent
//, outlet:'test' // Adding this does not work
}
]
}
]},
]
So, the RoutedDialogWrapperComponent
looks like this:
import { Component } from "@angular/core";
import { MatDialog } from "@angular/material/dialog";
import { RoutedDialogComponent } from "./routed-dialog.component";
import { Router, ActivatedRoute } from "@angular/router";
@Component({
template:''
})
export class RoutedDialogWrapperComponent{
constructor(private dialog:MatDialog, private router:Router,
private route: ActivatedRoute){
this.openDialog();
}
private openDialog(){
let dialog = this.dialog.open(RoutedDialogComponent);
dialog.afterClosed().subscribe(result => {
this.router.navigate(['../'],
{
relativeTo: this.route
});
});
}
}
and the HTML of the RoutedDialogComponent
like this:
<nav mat-tab-nav-bar>
<a mat-tab-link routerLink="/home/dialog2/first">First</a>
<a mat-tab-link>Second</a>
<a mat-tab-link>Third</a>
</nav>
<!-- without name it rendering goes wild and will hang -->
<router-outlet name='test'></router-outlet>
<!-- this router-outlet does not work ... -->
<!--
<router-outlet></router-outlet>
-->
In the end I want to have an url like: '/home/routed-dialog/first' and inside the dialog, under the tab-nav, I want to see the FirstComponent
but I don't know how to...
Other cases like having the correct tab 'activated' is something I'm confident enough about to fix, but on this one I need some help because my Angular knowledge (as goes for its slang) is pretty limited :-)