🐚 App Navigation Shell

Add a responsive navigation shell to the app

Add a basic navigation shell to the app and make it responsive on mobile.


Step 1 - Update the App Component

Nesting components inside each other is known as transclusion.

file_type_html app.component.html


Shell Breakpoint Logic

Make your navigation responsive by listening to breakpoints.

file_type_ng_component_ts shell.component.ts
import { Component } from '@angular/core';
import { BreakpointObserver, Breakpoints } from '@angular/cdk/layout';
import { Observable } from 'rxjs';
import { map, shareReplay } from 'rxjs/operators';

  selector: 'app-shell',
  templateUrl: './shell.component.html',
  styleUrls: ['./shell.component.scss']
export class ShellComponent {

  isHandset$: Observable<boolean> = this.breakpointObserver.observe([Breakpoints.Handset])
      map(result => result.matches),

  constructor(private breakpointObserver: BreakpointObserver) {}


Shell HTML

Full markup for the navigation shell.

file_type_html shell.component.html
<mat-sidenav-container class="sidenav-container">

  <!-- SIDENAV -->

  <mat-sidenav #drawer class="sidenav" fixedInViewport
      [attr.role]="(isHandset$ | async) ? 'dialog' : 'navigation'"
      [mode]="(isHandset$ | async) ? 'over' : 'side'"
      <a mat-list-item routerLink="/" (click)="drawer.close()">Home</a>
      <a mat-list-item routerLink="/login" (click)="drawer.close()">Login</a>
      <a mat-list-item routerLink="/kanban" (click)="drawer.close()">Kanban Demo</a>
      <a mat-list-item routerLink="/customers" (click)="drawer.close()">SSR Demo</a>

  <!-- TOP TOOLBAR-->

        aria-label="Toggle sidenav"
        *ngIf="isHandset$ | async">

        <mat-icon aria-label="Side nav toggle icon">menu</mat-icon>
      <span class="logo" routerLink="/">🔥 Angular Firestarter</span>

      <span class="fill-space"></span>
      <div *ngIf="!(isHandset$ | async)">
        <a mat-button routerLink="/kanban">🍱 Kanban Demo</a>
        <a mat-button routerLink="/customers">⚡ SSR Demo</a>

        <a mat-button routerLink="/login">🔑 Login</a>


      <!-- DROPDOWN MENU -->

      <button mat-icon-button [matMenuTriggerFor]="menu" aria-label="Example icon-button with a menu">
      <mat-menu #menu="matMenu">
        <a mat-menu-item href="https://fireship.page.link/slack">
          <span>Chat on Slack</span>

    <!-- TRANSCLUSION -->


Questions? Let's chat

Open Discord