My idea started when I thought of using a login view to protect my entire application (using guards) and force the user to login if they want to navigate the main component (planet.data in this case).
So I used lazy loading (not relevant) for planet.module and canActivate inside planet-routing.module.ts, but then couldn't navigate to planet-detail because the route couldn't match the URL segment. Displayed error: Cannot match any routes. URL Segment: 'rovers/411634'
I "solved" this problem by adding a planet-detail path as a child of 'rovers'. Now comes the part where I put the router-outlet inside the planet-data template and everything is fine until I click on a planet image to navigate to that image id. The planet-detail image is just below the planet data view. What am I missing? I'd like some guidance in the right direction please. Or any possible solution
Expected behavior: Navigate to image ID (only that path)
// planet-data.component.html
<div class="ui-g">
<div class="ui-g-12 ui-md-12">
<div class="ui-g-8">
<app-title *ngIf="pics"></app-title>
</div>
<div class="ui-g-4">
<app-dropdown-menu (selected)="onSelect($event)"></app-dropdown-menu>
</div>
</div>
<div class="ui-g-12">
<app-no-image class="margin" [cam]="true" [start]="true" *ngIf="!pics"></app-no-image>
</div>
<div>
</div>
<router-outlet></router-outlet>
<app-planet-view class="image" [pics]="pics"></app-planet-view>
</div>
<app-loader></app-loader>
// planet-detail.component.html
<div class="ui-g">
<app-image [picById]="picById"></app-image>
</div>
// planet-routing.module.ts
const planetRoutes: Routes = [
{
path: '',
component: PlanetDataComponent,
children: [
{
path: ':id',
component: PlanetDetailComponent,
canActivate: [AuthGuardService] },
],
canActivate: [AuthGuardService] },
];
@NgModule({
imports: [
RouterModule.forChild(planetRoutes)
],
exports: [RouterModule],
})
export class PlanetRoutingModule {}
// app.routing-module.ts
const routes: Routes = [
{ path: 'rovers', loadChildren: './planet/planet.module#PlanetModule' },
{ path: '', pathMatch: 'full', redirectTo: '/home' }
];
@NgModule({
imports: [RouterModule.forRoot(routes)],
exports: [RouterModule]
})
export class AppRoutingModule { }
// app.component.html
<header><app-header></app-header></header>
<main>
<router-outlet></router-outlet>
</main>
<footer><app-footer></app-footer></footer>