Setting a startup page in Blazor

PeteBal picture PeteBal · Jul 3, 2019 · Viewed 7.5k times · Source

The startup page in my Blazor application is Index.cshtml. I'd like to change the startup page to the homepage, namely my Home.cshtml.
I'm using vs2019, ASPNET CORE Blazor (0.9.0-preview3-19154-020).

Blazor Serverside has routing in the Startup.cs, which i think is for the services, and not for the pages...and is left as generated by creating a new Blazor project.

app.UseMvc(routes =>
{
   routes.MapRoute(name: "default", template: "{controller}/{action}/{id?}");
});

The client's startup has (as generated by a new Blazor project):

public void ConfigureServices(IServiceCollection services)
{
}

 public void Configure(IComponentsApplicationBuilder app)
{
     app.AddComponent<App>("app");
}

Do I need to register the routing in the client side startup.cs somehow?

the index.cshtml only has one line of code in it:

@page "/"

How do I change my 'startup' page from Index.cshtml to Home.cshtml?

I've looked in a lot of places and understand Blazor is 'experimental'. Feels like i'm working way to hard to change something this simple.

Answer

Mike Brind picture Mike Brind · Jul 4, 2019

Copy the @page directive including the route template:

@page "/"

from the Index.cshtml file to the Home.cshtml file, and then remove the Index.cshtml file, or provide a different route template to its @page directive e.g.

@page "/index"