npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@kovalenko/main-menu

v2.0.0

Published

An Angular service that automatically builds a hierarchical menu tree from your router configuration and keeps the page title in sync on every navigation.

Readme

@kovalenko/main-menu

An Angular service that automatically builds a hierarchical menu tree from your router configuration and keeps the page title in sync on every navigation.

Installation

npm install @kovalenko/main-menu

How it works

MainMenuService reads Router.config on startup and walks the route tree. A route is included in the menu when its data object contains a title field. Routes with dynamic segments (:param) or optional segments (?) are excluded automatically.

On every ActivationEnd event the service also updates the browser/app title using the deepest active route's pageTitle (or title if pageTitle is absent).

Route data fields

| Field | Type | Description | |---|---|---| | title | string | Menu item label. Required for a route to appear in the menu. | | pageTitle | string | Page title set on navigation. Falls back to title when omitted. | | access | T | Arbitrary access descriptor attached to the menu item (e.g. permission strings). Defaults to false when not provided. | | queryParams | Record<string, any> | Query parameters stored on the menu item. | | children | Routes | Alternative to the standard children key — lets you attach child routes via data instead. |

Basic usage

Add title to the route data to include a route in the menu:

// app.routes.ts
import { Routes } from '@angular/router';

export const routes: Routes = [
  {
    path: 'dashboard',
    component: DashboardComponent,
    data: { title: 'Dashboard' },
  },
  {
    path: 'reports',
    component: ReportsComponent,
    data: {
      title: 'Reports',         // menu label
      pageTitle: 'My Reports',  // browser tab title
      access: ['reports.read'],
    },
    children: [
      {
        path: 'monthly',
        component: MonthlyComponent,
        data: { title: 'Monthly' },
      },
    ],
  },
  {
    // no `title` → not included in the menu, but still sets the page title
    path: 'profile',
    component: ProfileComponent,
    data: { pageTitle: 'My Profile' },
  },
  {
    // dynamic segment → excluded from the menu automatically
    path: 'users/:id',
    component: UserComponent,
  },
];

Inject MainMenuService where you need the menu:

import { Component, inject } from '@angular/core';
import { RouterLink } from '@angular/router';
import { MainMenuService } from '@kovalenko/main-menu';

@Component({
  selector: 'app-nav',
  standalone: true,
  imports: [RouterLink],
  template: `
    @for (item of menu.items; track item.id) {
      <a [routerLink]="item.routerLink" [queryParams]="item.queryParams">
        {{ item.name }}
      </a>

      @if (item.children) {
        @for (child of item.children; track child.id) {
          <a [routerLink]="child.routerLink">{{ child.name }}</a>
        }
      }
    }
  `,
})
export class NavComponent {
  readonly menu = inject(MainMenuService);
}

Custom title service

By default the service uses Angular's built-in Title. To plug in your own implementation — for example, to translate titles or integrate with a third-party analytics library — extend MainMenuTitleService and provide it at the root level:

import { Injectable, Provider } from '@angular/core';
import { MainMenuTitleService } from '@kovalenko/main-menu';

@Injectable()
export class AppTitleService extends MainMenuTitleService {
  setTitle(title: string): void {
    document.title = `My App — ${title}`;
  }
}

// In your app config or providers array:
export const appConfig: ApplicationConfig = {
  providers: [
    { provide: MainMenuTitleService, useClass: AppTitleService },
  ],
};

When MainMenuTitleService is provided, it takes precedence over the default Title service.

MainMenuItem interface

Each item in MainMenuService.items (and nested children arrays) conforms to:

interface MainMenuItem<T = any> {
  id: string;                        // random unique identifier
  name: string;                      // from route data.title
  href?: string;                     // external link (set manually if needed)
  target?: string;                   // link target (set manually if needed)
  routerLink?: string[];             // built from the route path
  queryParams?: Record<string, any>; // from route data.queryParams
  access?: T;                        // from route data.access
  children?: MainMenuItem[];         // present when the route has eligible children
}

Access control

access is a pass-through field — the library does not evaluate it. Store whatever suits your application (permission strings, roles, boolean flags) and filter items in your template:

@for (item of menu.items; track item.id) {
  @if (!item.access || (item.access | hasPermissionPipe)) {
    <a [routerLink]="item.routerLink">{{ item.name }}</a>
  }
}

License

MIT