Redirect to external Website using Blazor Server

Viewed 48

I have a blazor-server website and I am trying to redirect the user away from my website to an external one f. e. https://www.google.com

I already tried using the NavigationManager, as I used it when redirecting between my sites but it didn't work. NavManager.NavigateTo("www.google.com");

This already took me hours of trying and googling and I would really appreciate any kind of help.

Thanks in advance.

3 Answers

I would use an anchor tag with an href.

<a href="https://www.google.com">Click to navigate.</a>

You need to JavaScript:

@inject IJSRuntime jsRuntime
await jsRuntime.InvokeAsync<object>("open", ""https://www.google.com/"", "_blank");

NavigationManager.NavigateTo works for absolute and relative URI.

Try adding the protocol: https://www.google.com

Doc

Related