Skip to main content

Command Palette

Search for a command to run...

Blazor Navigation

Quick down and dirty basic navigation

Updated
1 min read
Blazor Navigation
C

I am leanring to code as much as possible to aim to move into making a career out of programming/software development.

I am 42 years old so hopefully not to old to move careers but I love to learn so hopefully it will still gain me knowledge and new skills regardless.

Currently I work as engineer designer using SolidWorks to create press tooling and anodising plant drawings. Part of this role it also doing the internal IT support.

The below shows ways to navigate other than using the menu.

Routing for Pages

The routing generally goes at the top of the razor file.

//In the razor page:
@page "/pagetonavigateto"

//With a parameter value
@page "/pagetonavigateto/{id:int}"  //if the id is a int there are various types you can use such as bool, string etc.

Using <a> Tags

<a href="/pagetonavigateto/parametervalue">Click Here</a>

Using Buttons

In the razor file to navigate from

<button class="btn btn-primary" @onclick="Method">Click Here</button>

In the razor code section or the base class file

void Method()
{
    NavigationManager.NavigateTo("/pagetonavigateto/parametervalue");
}

You will also need to inject the NavigationManager into either the razor file or the base class file

//In the razor file
@inject NavigationManager NavigationManager

//In the base class file
[Inject]
NavigationManager NavManager { get; set; }