HerzogVolpe
HerzogVolpe

Reputation: 134

Redirect to external Website using Blazor Server

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.

Upvotes: 4

Views: 4905

Answers (3)

T.Trassoudaine
T.Trassoudaine

Reputation: 1365

NavigationManager.NavigateTo works for absolute and relative URI.

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

Doc

Upvotes: 3

Nb777
Nb777

Reputation: 2032

You need to JavaScript:

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

Upvotes: 1

Austin C
Austin C

Reputation: 185

I would use an anchor tag with an href.

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

Upvotes: 1

Related Questions