Blazor Navigation manager to specified URI (google.com)

660 Views Asked by At

i have a question about how to redirect page to certain page like google.com

I've tried with below but it's not working...

@inject NavigationManager NavigationManager

void()
{
 NavigationManager.NavigateTo("google.com");
}

but it moved to the link with ultimate uri. like localhost:3030/google.com

how could i move to a page like google.com in Blazor?

2

There are 2 best solutions below

0
On

If you want to visit Google page with click of button, you can do it like this

<button onclick="window.location='http://google.com'">Google</button>
0
On

While void() isn't valid C# I think we can guess what you are trying.

Just "google.com" will be seen as a local (relative) URI, that won't work.

Use:

//NavigationManager.NavigateTo("google.com");
  NavigationManager.NavigateTo("https://google.com");