-
-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: document standard and direct routing, introduce RoutingMode enum
- Loading branch information
Showing
8 changed files
with
99 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
# Routing in Htmxor | ||
|
||
Htmxor routing and Blazor Static Web Apps routing differ in ways that enhance htmx scenarios. In Htmxor, there are two types of routing: | ||
|
||
In Htmxor, there are **two** types of routing: | ||
|
||
- **Standard routing** | ||
- **Direct routing** | ||
|
||
The routing mode is determined by the presence or absence of [htmx headers](https://htmx.org/reference/#request_headers): | ||
|
||
``` | ||
if ( HX-Request is null || ( HX-Boosted is not null && HX-Target is null ) ) | ||
RoutingMode.Standard | ||
else | ||
RoutingMode.Direct | ||
``` | ||
|
||
Here's a detailed look at each mode: | ||
|
||
## Standard Routing | ||
|
||
Standard routing is used when the `HX-Request` header is missing, or when `HX-Boosted` is present and `HX-Target` is missing. | ||
|
||
In this mode, routing behaves like conventional Blazor Static Web Apps routing. The root component (typically App.razor or the component passed to `MapRazorComponents<TRootComponent>()` in `Program.cs`) is rendered. | ||
|
||
The root component usually renders a `<Router>` component that determines which `@page`-annotated component to render based on the HTTP request, using the layout specified for that page. | ||
|
||
Example: | ||
|
||
``` | ||
HTTP GET /my-page | ||
App -> Routes --> MainLayout --> MyPage | ||
``` | ||
|
||
## Direct Routing: | ||
|
||
Direct routing bypasses the root component (`App.razor`) and the standard layout (`MainLayout`). Instead, it routes directly to the component that matches the request. | ||
|
||
If the target component has a `HtmxLayout` attribute, that layout is rendered first. | ||
|
||
Example: | ||
|
||
``` | ||
HTTP GET /my-htmx-page | ||
HtmxLayout --> MyHtmxPage | ||
MyHtmxPage | ||
``` | ||
|
||
This allows `MyHtmxPage` to be rendered directly, optionally including a specified `HtmxLayout`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
using Microsoft.AspNetCore.Builder; | ||
using Microsoft.AspNetCore.Components; | ||
using Microsoft.AspNetCore.Components.Routing; | ||
|
||
namespace Htmxor.Http; | ||
|
||
/// <summary> | ||
/// Specifies the routing mode used by Htmxor to handle a HTTP request. | ||
/// </summary> | ||
public enum RoutingMode | ||
{ | ||
/// <summary> | ||
/// In standard routing mode is the same as normal Blazor Static Web app | ||
/// page routing, i.e. a request will go through the root component | ||
/// (specified by <see cref="RazorComponentsEndpointRouteBuilderExtensions.MapRazorComponents{TRootComponent}(Microsoft.AspNetCore.Routing.IEndpointRouteBuilder)"/>), | ||
/// and the root component will decide what to do with the request, | ||
/// usually rendering the <see cref="Router"/> component which will | ||
/// inspect the HTTP request and then render the component/page that | ||
/// matches the request, usually wrapped in a <see cref="LayoutComponentBase"/>. | ||
/// </summary> | ||
Standard, | ||
|
||
/// <summary> | ||
/// In direct routing mode, Htmxor will route direct to the component/page that | ||
/// matches the request. If the component specifies an <see cref="HtmxLayoutAttribute"/>, | ||
/// the component will be rendered within the layout specified by the attribute. | ||
/// </summary> | ||
Direct, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters