Author : MD TAREQ HASSAN | Updated : 2020/07/27

How routing works in blazor

The routing concept is same as “MVC”/”Razor pages” but in case of Blazor, each url corresponds to a component (Page component or Razor component) and that component will be rendered dynamically (while for MVC each url corresponds to a view and for Razor pages each url corresponds to a page)

Blazor WebAssembly:

Blazor Server

Basic Routing

Multiple route path for same page

@page "/employeeedit"
@page "/employeeedit/{EmployeeId}"
@using Foo.Models

@inherits EmployeeEditBase

<!-- ... ... ... -->

Route Template

To enable optional route: use @page "<route-template>" twice

@page "/users"
@page "/users/{id:int}"

// ... ... ...

Attribute Routing

[Route("/classonly")]  
public class ClassOnlyComponent: ComponentBase  
{  
   // ... ... ...
}