Home > Enterprise >  Redirect to external Website using Blazor Server
Redirect to external Website using Blazor Server

Time:08-26

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.

CodePudding user response:

NavigationManager.NavigateTo works for absolute and relative URI.

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

Doc

CodePudding user response:

You need to JavaScript:

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

CodePudding user response:

I would use an anchor tag with an href.

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