Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to reference files other than js and css? #2

Open
AlseinX opened this issue Jun 12, 2019 · 2 comments
Open

How to reference files other than js and css? #2

AlseinX opened this issue Jun 12, 2019 · 2 comments

Comments

@AlseinX
Copy link

AlseinX commented Jun 12, 2019

With client side hosting model, the resource path is _content/<AssemblyName>/<RecursivePath>. But when using this library to fix the server side hosting, the path becomes EmbeddedBlazorFile/<RecursivePath>.

If the component library only contains js and css files it would work properly (maybe not if there are some files with the same recursive path in different libraries) because the js and css is loaded with the _Host.cshtml that can use @Html.EmbeddedBlazorContent() to reference the js and css files with the same default path.

But what if something like an image file is referenced within a blazor component? What would be the proper path for making it work for both client side and server side hosting?

Btw, what does the default path EmbeddedBlazorFile/<RecursivePath> stand for rather than using _content/<AssemblyName>/<RecursivePath> that client side hosting uses?

@pcbender
Copy link

pcbender commented Aug 2, 2019

For me, I copied the favicon.ico file into the content\dist folder of my library. The file is available to the browser at EmbeddedBlazorFile/dist/favicon.ico.

@SeppPenner
Copy link
Contributor

SeppPenner commented Sep 6, 2019

It's quite simple to get the whole wwwroot folder automatically in a server-side project:

  1. Adjust your _Host.cshtml file in the server project or create it if it doesn't exist, copy the index.html content from your client side project to it and add the following at the top:
@page
@using EmbeddedBlazorContent

@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
  1. In the head section of the _Host.cshtml file in the server project, add @Html.EmbeddedBlazorContent() like, e.g.
<html>
    <head>
        @Html.EmbeddedBlazorContent()
    <head>
</html>
  1. In your server project startup class, add using EmbeddedBlazorContent; to the usings section and the following code to the Configure method in your server project startup class:
app.UseEmbeddedBlazorContent(typeof(BaseMatComponent).Assembly);
app.UseClientSideBlazorFiles<Startup>();
app.UseStaticFiles();

app.UseStaticFiles(
    new StaticFileOptions
    {
        FileProvider = new PhysicalFileProvider(Path.GetFullPath("..\\ClientProject\\wwwroot"))
    });
  1. Pray that it works. In preview8, it did, in preview9 I'm having some issues (I didn't find the exact error yet).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants