I just created my first .Net 8 Blazor Web App using the new template. I want to remove the Counter, as I will be modifying the app for my own purposes. I run into a problem when I remove the last line of the following boilerplate code:
app.MapRazorComponents<App>()
.AddInteractiveServerRenderMode()
.AddInteractiveWebAssemblyRenderMode()
.AddAdditionalAssemblies(typeof(Counter).Assembly);
Remove that line, then run the app and you get a 404. Put it back, and it runs fine.
How do I get rid of the counter code? It’s driving me nuts!
>Solution :
Look closely at that line. It says typeof(Counter).Assembly.
You’re not removing counter, your removing the instruction for the SSR Razor/Blazor to read any routes [defined by "@page …"] in the assembly to which Counter belongs.
That line:
.AddAdditionalAssemblies(typeof(Counter).Assembly);
Needs to refer any object in the Client Project.
In this example the solution is called SO77672168 [your question ID].
This line:
app.MapRazorComponents<App>()
.AddInteractiveServerRenderMode()
.AddInteractiveWebAssemblyRenderMode()
.AddAdditionalAssemblies(typeof(SO77672168.Client._Imports).Assembly);
Adds the middleware to the Http request pipeline, and instructs the server side router to not only look in it’s own assembly for routes, but also in the assembly to which SO77672168.Client._Imports belongs.