---
title: "@design.estate/navigation"
---
# @designestate/navigation
A module for opinionated navigation abstraction.

## Install
To use `@designestate/navigation` in your project, run:

```bash
npm install @designestate/navigation --save
```

This will install the package and add it to your project's dependencies.

## Usage
The `@designestate/navigation` module is designed to simplify the creation and management of navigational structures in your application. It provides a way to abstract navigation into manageable components, allowing for a more modular and maintainable codebase. Below are examples and explanations on how to utilize this module effectively in your projects.

### Getting Started
First, ensure that you import the necessary classes from the module:

```typescript
import { NavigationManager, NavigationEntry } from '@designestate/navigation';
```

### Creating a Navigation Manager
The `NavigationManager` acts as the central point for managing navigation entries and can be linked with other navigation managers to create a more complex navigation structure. Here's how you can initialize a new `NavigationManager`:

```typescript
const myNavigationManager = new NavigationManager();
```

### Adding Navigation Entries
`NavigationEntry` instances represent individual navigational elements. These can be pages, links, or any other components that you navigate to in your application. You can add navigation entries to the navigation manager like this:

```typescript
import { NavigationEntry } from '@designestate/navigation';

const dashboardNavEntry = new NavigationEntry();
dashboardNavEntry.level = 0;
dashboardNavEntry.group = 'main';
dashboardNavEntry.groupRanking = 1;
dashboardNavEntry.iconUrl = 'path/to/icon/url';
dashboardNavEntry.id = 'dashboard';
dashboardNavEntry.name = 'Dashboard';
dashboardNavEntry.callBack = (idArg?: string) => {
  console.log(`Navigating to ${idArg}`);
};

myNavigationManager.addNavigationEntry(dashboardNavEntry);
```

### Compiling Navigation
Once you have added all necessary navigation entries, you can compile the navigation structure. This process transforms the added entries into a `CompiledNavigation` instance, which can be used to render navigational components or manage routing:

```typescript
myNavigationManager.compile().then(compiledNavigation => {
  // Use the compiledNavigation instance as needed
});
```

### Observing Navigation Changes
`NavigationManager` provides an observable you can subscribe to for reacting to navigation changes. Whenever the navigation structure is compiled or updated, the observable emits a `CompiledNavigation` instance:

```typescript
myNavigationManager.compiledNavigationObservable.subscribe(compiledNavigation => {
  // Handle navigation change
});
```

### Advanced Usage
#### Hierarchical Navigation
For complex applications, you might need hierarchical navigation. You can add a `NavigationManager` instance to another `NavigationManager`, enabling hierarchical navigation management:

```typescript
const subNavigationManager = new NavigationManager();
// Configure subNavigationManager

myNavigationManager.addNavigationManager(subNavigationManager);

// When you compile myNavigationManager, it will also include navigation entries from subNavigationManager
```

#### Dynamic Navigation Entries
Navigation entries can be dynamically added or removed based on application state or user permissions. This allows for a flexible and adaptive navigation structure:

```typescript
const adminNavEntry = new NavigationEntry();
// Configure adminNavEntry for admin level access

if (user.isAdmin) {
  myNavigationManager.addNavigationEntry(adminNavEntry);
}

// You can also remove entries dynamically if needed
```

## Conclusion
The `@designestate/navigation` module offers a powerful and flexible way to manage navigation in your applications. By abstracting navigation into manageable components, it facilitates better organization and maintenance of your codebase. With the ability to create hierarchical and dynamic navigations, this module can cater to a wide range of application structures and scenarios.

Remember, the above examples are just the starting point. Explore the module further to harness its full capabilities in building intuitive and maintainable navigation structures for your applications.



## License and Legal Information

This repository contains open-source code that is licensed under the MIT License. A copy of the MIT License can be found in the [license](license) file within this repository. 

**Please note:** The MIT License does not grant permission to use the trade names, trademarks, service marks, or product names of the project, except as required for reasonable and customary use in describing the origin of the work and reproducing the content of the NOTICE file.

### Trademarks

This project is owned and maintained by Task Venture Capital GmbH. The names and logos associated with Task Venture Capital GmbH and any related products or services are trademarks of Task Venture Capital GmbH and are not included within the scope of the MIT license granted herein. Use of these trademarks must comply with Task Venture Capital GmbH's Trademark Guidelines, and any usage must be approved in writing by Task Venture Capital GmbH.

### Company Information

Task Venture Capital GmbH  
Registered at District court Bremen HRB 35230 HB, Germany

For any legal inquiries or if you require further information, please contact us via email at hello@task.vc.

By using this repository, you acknowledge that you have read this section, agree to comply with its terms, and understand that the licensing of the code does not imply endorsement by Task Venture Capital GmbH of any derivative works.
