Blazor Navigation

Blazor Navigation

Quick down and dirty basic navigation

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()

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
NavigationManager NavManager { get; set; }