-
Notifications
You must be signed in to change notification settings - Fork 25.1k
Split the Routing & Navigation article #36145
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
|
|
||
| > [!IMPORTANT] | ||
| > Code examples throughout this article show methods called on `Navigation`, which is an injected <xref:Microsoft.AspNetCore.Components.NavigationManager> in classes and components. | ||
| Routing in Blazor is achieved by providing a route template to each accessible component in the app with an [`@page`](xref:mvc/views/razor#page) directive. When a Razor file with an `@page` directive is compiled, the generated class is given a <xref:Microsoft.AspNetCore.Mvc.RouteAttribute> specifying the route template. At runtime, the router searches for component classes with a <xref:Microsoft.AspNetCore.Mvc.RouteAttribute> and renders whichever component has a route template that matches the requested URL. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| Routing in Blazor is achieved by providing a route template to each accessible component in the app with an [`@page`](xref:mvc/views/razor#page) directive. When a Razor file with an `@page` directive is compiled, the generated class is given a <xref:Microsoft.AspNetCore.Mvc.RouteAttribute> specifying the route template. At runtime, the router searches for component classes with a <xref:Microsoft.AspNetCore.Mvc.RouteAttribute> and renders whichever component has a route template that matches the requested URL. | |
| Routing in Blazor is achieved by providing a route template to each accessible component in the app with an [`@page`](xref:mvc/views/razor#page) directive. When a Razor file with an `@page` directive is compiled, the generated class is given a <xref:Microsoft.AspNetCore.Components.RouteAttribute> specifying the route template. At runtime, the router searches for component classes with a <xref:Microsoft.AspNetCore.Components.RouteAttribute> and renders whichever component has a route template that matches the requested URL. |
| ## Route templates | ||
| ## ASP.NET Core endpoint routing integration | ||
|
|
||
| *This section applies to Blazor Web Apps and Blazor Server apps operating over a circuit.* |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The content for .NET 8+ really only covers endpoint routing integration for Blazor Web Apps. The Blazor Server content is only shown for earlier .NET versions. I think this line needs to be within the version range monikers and adjusted accordingly.
|
|
||
| :::moniker range=">= aspnetcore-8.0" | ||
|
|
||
| The <xref:Microsoft.AspNetCore.Components.Routing.Router> component enables routing to Razor components and is located in the app's `Routes` component (`Components/Routes.razor`). | ||
| A Blazor Web App is integrated into [ASP.NET Core Endpoint Routing](xref:fundamentals/routing). An ASP.NET Core app is configured to accept incoming connections for interactive components with <xref:Microsoft.AspNetCore.Builder.RazorComponentsEndpointRouteBuilderExtensions.MapRazorComponents%2A> in the `Program` file. The default root component (first component loaded) is the `App` component (`App.razor`): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The components don't have to be interactive to respond to requests:
| A Blazor Web App is integrated into [ASP.NET Core Endpoint Routing](xref:fundamentals/routing). An ASP.NET Core app is configured to accept incoming connections for interactive components with <xref:Microsoft.AspNetCore.Builder.RazorComponentsEndpointRouteBuilderExtensions.MapRazorComponents%2A> in the `Program` file. The default root component (first component loaded) is the `App` component (`App.razor`): | |
| A Blazor Web App is integrated into [ASP.NET Core Endpoint Routing](xref:fundamentals/routing). An ASP.NET Core app is configured with endpoints for routable components and the root component to render for those endpoints with <xref:Microsoft.AspNetCore.Builder.RazorComponentsEndpointRouteBuilderExtensions.MapRazorComponents%2A> in the `Program` file. The default root component (first component loaded) is the `App` component (`App.razor`): |
Fixes #35683
Fixes #36190
Splits roughly along
Routercomponent andNavLink/NavigationManagerlines.Not Found spans them, so there's a little bit on the
NotFoundPageparam in the Routing article with the rest in the Not Found responses section of the new Navigation article.I'm not planning a review/update of all sections at this time. It would slow me down by a couple of days in reaching the next Blazorfy IT!™ issue, but let me know if you would like to go for a full review on all of this guidance.
I'm inlining code examples because it's taking an awful lot of time ... i.e., 💰💰💰 ... to update sample cross-links every release for no great benefit. The code isn't changing and isn't likely to change for these examples. I'm stripping off the
<PageTitle>markup because it came in at 6.0, making the examples apply universally.Outlines
Routing article
OnNavigateAsyncOnNavigateAsync<Navigating>contentNavigation article
NavLinkcomponentnullNavLinkcomponents via reflectionInternal previews
Toggle expand/collapse