Home > Blockchain >  index.html button navigation to razor page
index.html button navigation to razor page

Time:11-05

I have an application where we have a button in index.html. So just wanted to navigate from index.html to another razor page which is in PAGES folder called

dashboard.razor 

I am newbie to blazor applications,please help.

CodePudding user response:

Use NavigationManager.

@inject NavigationManager NavigationManager;
@code {
    private void MyButtonClick()
    {
        this.NavigationManager.NavigateTo("/dashboard");
    }
}

CodePudding user response:

First, you have to assign a path for the dashboard.razor by the @page directive on the above of the component. For example:

@page "/dashboard"  

Now you can access to dashboard.razor from everywhere by /dashboard. For example, for the Index.html button, you can do it such as below:

<button onclick="location.href = 'www.yoursite.com/dashboard';" id="myButton"  >Dashboard</button>
  • Related