Reputation: 191
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.
Upvotes: 11
Views: 3738
Reputation: 835
Hey we also found ourself with the same issue.
A better solution would be to specify
<base href="~/"/>
in the head of the html and just referencing <script src="_framework/blazor.server.js"/>
so
<html>
<head>
<base href="~/"/>
</head>
<body>
<script src="_framework/blazor.server.js"/>
</body>
</html>
Upvotes: 6
Reputation: 191
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.
Upvotes: 7