You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 4-6.RSVP
Socket
Book a DemoInstallSign in
Socket

angular-router-menus

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

angular-router-menus

Angular Router menus that build itself on-the-fly with options

2.0.1
Source
npmnpm
Version published
Weekly downloads
11
-15.38%
Maintainers
1
Weekly downloads
 
Created
Source

Angular Router Menus

Simplify your Angular applications navigation by defining menu entries directly at the route itself. It is fully typed and defined by your requirements, build as many navigation's as you like. It also supports nesting menus so you can build yourself cool dropdowns. All menus are build and injected into several injection tokens, so you can import them anywhere.

pnpm add angular-router-menus

[!TIP] Zero dependencies and no performance bottleneck!

  • Installation
  • Usage
  • Configuration
  • Examples

Installation

  • Install the package
  • Create a type definition file or add to yours
    • declare type Menus = "main" | "aside"
    • Adjust menus by your needs, you will configure them later
  • In your main.ts file import and configure the library
  • Make sure you have all your declared menus in the menus array
  • You must need a preloading strategy because I use internal api's
    • NoPreloading is the default in Angular
void bootstrapApplication(AppComponent, {
	providers: [
		provideRouter(routes, withPreloading(NoPreloading)),
		provideRouterMenus(routes, ["main"], {
			defaultMenu: "main", // 👋🏻
			debug: !environment.production,
		}),
	],
}).catch((error) => {
	console.error(error);
});

Usage

@Component({
	selector: "app-root",
	templateUrl: "./app.component.html",
	styleUrl: "./app.component.scss",
	changeDetection: ChangeDetectionStrategy.OnPush,
	imports: [RouterOutlet, RouterLink, RouterLinkActive],
})
export class AppComponent {
	readonly menu = inject(RouterMenusService).use("main"); // 👋🏻
}
<ul>
	@for (item of menu(); track item.href) {
	<li>
		<a [routerLink]="item.href" routerLinkActive="active">{{ item.label }}</a>
	</li>
	}
</ul>

Configuration

For details on menu items configuration, please take a look at the interfaces and its documentation here: projects/angular-router-menus/src/lib/menu.ts

PropertyDescription
defaultMenuIf not defined via in this is the default menu.
debugEnables debugging, because of internal API use I omit all errors.
menuOptionsObject of menu name and an object. Please see MenuOptions.

MenuOptions

PropertyDescription
sortOrderSort menu by "asc" or "desc".

Examples

For an example go to projects/app and run it :)

Keywords

angular

FAQs

Package last updated on 07 May 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts