the first image shows the routing structure of my current position
the second one shows how it looks like in reality
the problem before I implemented the children (so basically the same structure, but the part where stuff is maked red was just not there yet) was that the guilds on the side were reloaded each time, so as soon as a guild was selected the sidebar was empty for ~1-2 seconds
I ignored that at first and was focosing on the dashboards content itself and implemented the route children
after that the guilds on the side didn't reload again after clicking which wasn't was was supposed to happen; the child routes were only for the content of the dashboard itself, not the selector on the side
below is the sidebar.component.ts file and below that my routing
what I want to have in the end is what is shown in my drawing pluss the sidebar reloading, but with the catch that there isn't a new api request every time, instead just this part in my html (guild.id === selectedGuild ? '' : ' rounded-r-2xl mr-2') should react
sidebar.component.ts
import {Component, Input} from '@angular/core';
import {BotApiService} from "../../bot-api.service";
import {BotGuild, PartialGuild} from "../../datatypes";
import {AuthService} from "../../auth.service";
@Component({
selector: 'app-sidebar',
templateUrl: './sidebar.component.html',
styleUrls: ['./sidebar.component.css']
})
export class SidebarComponent {
@Input() selectedGuild: number = 0;
userGuilds: PartialGuild[] = [];
botGuilds: BotGuild[] = [];
guilds: PartialGuild[] = [];
optionalGuilds: PartialGuild[] = []
constructor(private _botAPI: BotApiService, private _auth: AuthService) {}
ngOnInit(): void {
this._botAPI.getGuilds()
.subscribe(data => this.botGuilds = data);
this._auth.fetchUserGuilds()
.subscribe(data => {
this.userGuilds = [];
for (const guild of data) {
if (guild.owner) {
this.userGuilds.push(new PartialGuild(guild));
}
}
this.guilds = [];
this.guilds = this.userGuilds;
});
}
}
sidebar.component.html
<div class="grid auto-rows-min h-full ml-2 overflow-y-auto hide-scroll">
<app-sidebar-guild
*ngFor="let guild of guilds;"
[guild]="guild"
[routerLink]="'/dashboard/' + guild.id"
[ngClass]="'sidebar-guild' + (guild.id === selectedGuild ? '' : ' rounded-r-2xl mr-2')"
></app-sidebar-guild>
</div>
routes within app.module.ts
const routes: Routes = [
{path: '', component: HomeComponent},
{path: 'callback', component: CallbackComponent},
{path: 'dashboard', component: DashboardComponent},
{
path: 'dashboard/:id',
component: DashboardComponent,
children: [
{path: 'overview', component: OverviewComponent},
{path: 'settings', component: SettingsComponent},
{path: 'statistics', component: StatisticsComponent}
]
},
{path: '**', component: NotFoundComponent},
]```