dev.tirsvad.dk
Tirsvad Website: A Clean Architecture .NET solution using Blazor WebAssembly for modern, cloud-ready web applications. Supports SQLite/MySQL, containerization, and follows best practices for maintainability and scalability.
DotNet.Examples.Navigation.Horizontal Directory Reference
Directory dependency graph for DotNet.Examples.Navigation.Horizontal:
src/WebUI/WebUI/wwwroot/projects/TirsvadWeb/DotNet.Examples.Navigation.Horizontal

Detailed Description

[![downloads][downloads-shield]][downloads-url][![Contributors][contributors-shield]][contributors-url][![Forks][forks-shield]][forks-url][![Stargazers][stars-shield]][stars-url][![Issues][issues-shield]][issues-url][![License][license-shield]][license-url][![LinkedIn][linkedin-shield]][linkedin-url]

Logo Navigation Horizontal Example

Overview

This project demonstrates a horizontal navigation menu in a Blazor WebAssembly application. On branch 01-MenuBasedOnJson, the menu structure is defined in the navBar.json file (not in code), making it easy to customize the navigation without recompiling. It is designed as an example for building dynamic, multi-level navigation menus in modern .NET Blazor applications.

The solution is organized into several projects following clean architecture principles:

Features

How It Works

  1. Menu Data: The menu structure is defined in the navBar.json file located at src/Examples.Navigation.Horizontal.WebUI/Examples.Navigation.Horizontal.WebUI/wwwroot/navBar.json. Each menu item can have nested SubItems for submenus.
  2. Dependency Injection: The infrastructure project registers the repository and services for dependency injection, making them available to the Blazor components.
  3. Blazor Components: The TopNavBar and MenuFragmentRender components render the navigation bar and its items recursively, supporting multi-level dropdowns.
  4. UI Rendering: The navigation bar is rendered horizontally at the top of the page, with dropdowns for submenus. The menu is responsive and collapses on smaller screens.

Project Structure

Getting Started

Prerequisites

Running the Application

  1. Clone the repository:
    git clone https://github.com/Tirsvad/TirsvadWeb.DotNet.Examples.Navigation.Horizontal.git
    cd TirsvadWeb.DotNet.Examples.Navigation.Horizontal
  2. Restore dependencies:
    dotnet restore
  3. Build the solution:
    dotnet build
  4. Run the WebUI host project (server):
    dotnet run --project src/Examples.Navigation.Horizontal.WebUI/Examples.Navigation.Horizontal.WebUI/Examples.Navigation.Horizontal.WebUI.csproj
  5. Open your browser and navigate to the provided URL (usually https://localhost:5001 or similar).

Running with Docker-Compose

  1. Build and run the application using Docker-Compose:
    docker-compose up --build
  1. Open your browser and navigate to http://localhost:5401 to see the application running.

Customization

Editing the Menu Structure (branch 01-MenuBasedOnJson)

To modify the menu structure, edit the navBar.json file located at:

src/Examples.Navigation.Horizontal.WebUI/Examples.Navigation.Horizontal.WebUI/wwwroot/navBar.json

Example navBar.json structure:

{
"NavBar": {
"Title": "TirsvadWeb<br />Web Examples"
},
"NavItems": [
{
"Id": "8fdd56d5-fd85-46cb-9c75-5192aca81dc2",
"Title": "Home",
"Url": "/",
"Order": 1
},
{
"Id": "d1c9e5b8-3a2f-4c9e-8b6a-1f2e3d4c5b6a",
"Title": "Menu 1",
"Url": "/",
"Order": 2,
"SubItems": [
{
"Id": "a1b2c3d4-e5f6-7890-abcd-1234567890ab",
"Title": "SubMenu 1.1",
"Url": "/",
"Order": 1
}
]
}
]
}

After saving changes to navBar.json, restart the application to see the updated menu.

To change the UI, update the Blazor components in the Components/TopNavBar folder.

License

This project is licensed under the MIT License. See the [LICENSE](LICENSE) file for details.

Branches