1

Trying to replace HREF upon click on Anchor with Blazor.

So in pseudo;

click => calls function => replaces HREF => triggers open event, but targets new HREF

couldn't make it happen, what should be the syntax?

<a href="javascript: void(0)" @onclick="@(()=> GetCloudFileSignedUrl(context.FileName))">@context.FileName</a>

Side note Please do not reference https://github.com/aspnet/AspNetCore/issues/5545. I'm asking how to replace the HREF value with an external address which is irrelevant to that issue since I'm OK to use javascript: void(0) at this point.

cilerler
  • 9,010
  • 10
  • 56
  • 91
  • 1
    Using `NavigationManager.NavigatTo, check [NavigationManager cheatsheet](https://stackoverflow.com/a/53448294/842935) – dani herrera Oct 20 '19 at 06:53
  • @daniherrera I appreciate the quick response, it is almost precisely what I'm looking for, the only issue is I need to open a new page, where it replaces the existing one, looking on the internet to find a way, just wanted to share. Thanks again. – cilerler Oct 20 '19 at 07:01
  • @daniherrera found the answer at here https://github.com/aspnet/AspNetCore/issues/8703#issuecomment-475320842 Thanks again – cilerler Oct 20 '19 at 07:18

1 Answers1

0

Thanks to @daniherrera I started to look into the right places and figured it out the answer in here

        [Inject] public NavigationManager NavigationManager { get; set; }
        [Inject] public IJSRuntime JsRuntime { get; set; }
        public async Task NavigateToUrlAsync(string url, bool openInNewTab)
        {
            if (openInNewTab)
            {
                await JsRuntime.InvokeAsync<object>("open", url, "_blank");
            }
            else
            {
                NavigationManager.NavigateTo(url);
            }
        }
cilerler
  • 9,010
  • 10
  • 56
  • 91