Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

160
Views
How to reference local JS modules in Blazor components?

On Dotnetconf two weeks ago I heard it is now possible to include local Javascript files in Blazor components. That sounds very interesting. I guess the approach is still to use JSIniterop and reference the module file.

BUT how do you reference the JS file ??? I have tried all possible creative variants but so far without success.

I am surprised to Google everywhere but find no guides or sample yet on this. All hints are appreciated.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You can create .js code file next to .razor.cs file and load that file in runtime. It's described here. Also I found presentation of this feature here and github repo here.

Let's say that you have ComponentA with ComponentA.razor, ComponentA.razor.cs and ComponentA.razor.js files in Pages folder. You can load this module during component's initialization like so:

[Inject]
public IJSRuntime JS { get; set; }

private IJSObjectReference module { get; set; }

protected override async Task OnInitializedAsync()
{
    module = await JS.InvokeAsync<IJSObjectReference>("import", "./Pages/ComponentA.razor.js");
}

But if your component is defined in a component library project then you have to use different file path. For example if your project is named AppComponents then this path would be ./_content/AppComponents/ComponentA.razor.js.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!