Daniel Vega
Daniel Vega

Reputation: 578

Moving blazor components to a shared components project

I'm trying to have my blazor server to blazor wasm. we a good part of the project developed already but we want to move anyway. There is where the doubt comes. I created a project of components to be able to share them, but I'm trying to move the pages as well there, and now the routing is picking up nothing and got what is in the index and nothing more. how I do make my app aware that it should render pages from a project under .components (the blazor components library) and not what is under .cliente (the blazor server project)

Upvotes: 0

Views: 1423

Answers (1)

Alamakanambra
Alamakanambra

Reputation: 7851

I assume that you have structure with these 3 projects:

  • ClientWasm -> The project where is your index page and where you want to use your components
  • Components -> Project with components (of type <Project Sdk="Microsoft.NET.Sdk.Razor">)
  • ClientServer -> Old Blazor server project

Now. If you want to use component in ClientWasm that is located in Components you have to add reference to Components in ClientWasm

If you have pages with routes (in Components) you need to add additional Assemblies in ClientWasm:

@*App.razor in ClientWasm project*@
<Router AppAssembly="@typeof(Program).Assembly"
            AdditionalAssemblies="new[] { typeof(Components.SomePage).Assembly}">

Upvotes: 1

Related Questions