Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting a startup page in Blazor

Tags:

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.

like image 772
PeteBal Avatar asked Jul 03 '19 19:07

PeteBal


People also ask

How do I create a Blazor start page?

Configure a manual start in the wwwroot/index. html file (Blazor WebAssembly) or Pages/_Layout. cshtml file (Blazor Server): Add an autostart="false" attribute and value to the <script> tag for the Blazor script.

Is anyone using Blazor in production?

Yes, Blazor is ready to be used in production, it is a life changer, Blazor is a framework that optimizes development speed, helps considerably reducing code duplication and inconsistencies between front-end and api/backend models, and in turn it helps reducing bugs and development costs, in top of that, since Blazor ...

Is Blazor worth learning 2021?

If you were considering a Windows desktop application (built on something like WPF), Blazor is a more future-forward choice. But if you're a business building modern, public web applications, there's very little chance you'll recommend a client start with Blazor today.

How can I get current page name in Blazor?

You can get the current page title in Blazor by using the “title” property of the document object in JavaScript and by using a . JavaScript interop since there is no DOM accessibility in Blazor.


1 Answers

Just put @page "/" on top of your page you want to be default. Remove @page "/" from Index.razor

@page "/" @page "/fetchdata" 
like image 189
Zeus Avatar answered Sep 19 '22 13:09

Zeus