I've added Razor Page Component to my existing MVC application
Pages/Test.razor
@page "/test"
<h1>Hello World!</h1>
@code {
}
Program.cs
var builder = WebApplication.CreateBuilder(args);
// Add services to the container.
builder.Services.AddControllersWithViews();
builder.Services.AddServerSideBlazor();
builder.Services.AddRazorPages();
var app = builder.Build();
// Configure the HTTP request pipeline.
if (!app.Environment.IsDevelopment())
{
app.UseExceptionHandler("/Home/Error");
}
app.UseStaticFiles();
app.UseRouting();
app.UseAuthorization();
app.UseEndpoints(endpoints =>
{
endpoints.MapControllerRoute(
name: "default",
pattern: "{controller=Home}/{action=Index}/{id?}");
endpoints.MapRazorPages();
endpoints.MapBlazorHub();
});
app.Run();
Views/Shared/_Layout.cshtml
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>@ViewData["Title"] - MVCApp</title>
<link rel="stylesheet" href="~/lib/bootstrap/dist/css/bootstrap.min.css" />
<link rel="stylesheet" href="~/css/site.css" asp-append-version="true" />
<link rel="stylesheet" href="~/MVCApp.styles.css" asp-append-version="true" />
<base href="/"/>
<script src="_framework/blazor.server.js"></script>
...
but it doesn't work: I get 404 on /test
What am I missing to make Razor Component's routing work with MVC routing?

You need to install the
Microsoft.AspNetCore.Componentspackage and add the_Host.cshtml,App.razor,_Imports.razorfiles to your MVC project._Imports.razor:
_Host.cshtml:
App.razor:
Your Endpoints:
Test Result:
If you want to use the UI in Blazor, you can also copy
MainLayout.razorfrom a Blazor App and use it inApp.razorlike this:Note that if you do this, your default page will be a Razor Component with
@page "/"defined instead ofIndex.cshtml.