How do I use blazor server-side inside a razor component library using areas?

☆樱花仙子☆ 提交于 2019-12-23 12:56:19

问题


I have an existing .net core 3.0 preview 7 web application. My application is mainly razor-pages organized into areas eg. Admin, Sales, etc. I am able to successfully use a blazor component if I put it at the root of the application, however, if I move the component to an RCL I can access the component but it is not responsive (clicking the button for the counter example does not increment the count).

I want to be able to go localhost/Admin/RazorPageContainingBlazorComponent or localhost/Sales/AnotherRazorPageContainingBlazorComponent

I get this error in chrome dev tools: ''' Error: Failed to complete negotiation with the server: Error

https://localhost:5000/myfeature/_blazor/negotiate 404 '''

I believe this is caused by the signalR hub being mapped to https://localhost:5000/, but I not sure how to add additional blazor hub mappings or how to change blazor.server.js to to use the root hub.


回答1:


After digging though both signalR documentation and the blazor.server.js file I was able to come up with a solution. Adding the code below to you're layout file configures the signalR hub to use an absolute path instead of a relative path.

<script src="~/_framework/blazor.server.js" autostart="false"></script>
<script>
    Blazor.start({
        configureSignalR: function (builder) {
            builder.withUrl("/_blazor");
        }
    });
</script>

This allows razor components to be used directly in a razor class library, using area routing.



来源:https://stackoverflow.com/questions/57366355/how-do-i-use-blazor-server-side-inside-a-razor-component-library-using-areas

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!