This code will help you to understand how to navigate from one component to another component in ASP.NET Core Blazor.
Navigating from link
There are two ways to link pages in Blazor:
<h3>Anchor Link</h3> <p> <a href="/navigate1">Navigate 1</a><br /> </p> <h3>Nav Link</h3> <p> <NavLink href="/navigate2">Navigate 2</NavLink><br /> </p>
Navigate from code
We can navigate to another component programmatically using the NavigationManager service:
@page "/page1" @inject NavigationManager UriHelper <h3>Naviagte to another component Programatically</h3> <button @onclick=@Navigate>Navigate</button> @code { void Navigate() { UriHelper.NavigateTo("page2"); } }
total answers (1)
start bookmarking useful questions and collections and save it into your own study-lists, login now to start creating your own collections.
Navigating from link
There are two ways to link pages in Blazor:
Navigate from code
We can navigate to another component programmatically using the NavigationManager service:
- Inject the service @inject directive.
- Use the NavigateTo() method for navigation.
need an explanation for this answer? contact us directly to get an explanation for this answer