SuperAPI AI Directory

d2-05-main-menu

General & other

View repository

Updated 10-16 09:30

About this skill

Day 2 · Step 5 — Main menu with navigation

up-app/src/app/pages/menu/menu.component.ts (standalone component):

  • Display the program/application name as a heading.
  • Provide a Go to Search button → router.navigate(['/<entity>']).
  • Provide an Add New button → router.navigate(['/<entity>/new']).
  • Use Tailwind CSS for styling (centered layout, button spacing).

Route table (app.routes.ts) — add the menu route as the landing page:

{ path: '', component: MenuComponent },  // default/home route
{ path: '<entity>', component: <Entity>SearchComponent },
{ path: '<entity>/new', component: <Entity>FormComponent },
{ path: '<entity>/:id/edit', component: <Entity>FormComponent },

Update app.component.ts to show <router-outlet/> (already done in d2-00).

Component TypeScript:

import { Component } from '@angular/core';
import { Router } from '@angular/router';
import { CommonModule } from '@angular/common';

@Component({
  selector: 'app-menu',
  standalone: true,
  imports: [CommonModule],
  templateUrl: './menu.component.html',
  styleUrls: ['./menu.component.css']
})
export class MenuComponent {
  programName = 'CRUD Application';

  constructor(private router: Router) {}

  onGoToSearch() {
    this.router.navigate(['/<entity>']);
  }

  onAddNew() {
    this.router.navigate(['/<entity>/new']);
  }
}

Template (with cohesive design):

<div class="min-h-screen bg-gradient-to-br from-gray-50 to-gray-100 flex items-center justify-center p-md">
  <div class="bg-white rounded-2xl shadow-2xl p-xl text-center max-w-md w-full">
    <!-- Logo/Title -->
    <div class="mb-xl">
      <h1 class="text-5xl font-bold text-gray-900">{{ programName }}</h1>
      <p class="text-muted mt-md text-lg">Manage your data with ease</p>
    </div>

    <!-- Description -->
    <p class="text-gray-600 mb-xl text-base leading-relaxed">
      Select an action below to get started with managing your data.
    </p>

    <!-- Buttons -->
    <div class="flex flex-col gap-md">
      <button
        (click)="onGoToSearch()"
        class="w-full bg-primary hover:bg-blue-600 text-white font-semibold px-lg py-md rounded-lg transition shadow-md hover:shadow-lg"
      >
        📋 Browse <Entity>
      </button>

      <button
        (click)="onAddNew()"
        class="w-full bg-secondary hover:bg-green-600 text-white font-semibold px-lg py-md rounded-lg transition shadow-md hover:shadow-lg"
      >
        ✚ Add New <Entity>
      </button>
    </div>

    <!-- Footer -->
    <p class="text-muted text-sm mt-xl">
      Powered by Angular + Tailwind CSS
    </p>
  </div>
</div>

No redeploy required (static menu component). Test by running the app and verifying the menu displays with buttons that navigate correctly.