egil / Htmxor

Supercharges Blazor static server side rendering (SSR) by seamlessly integrating the Htmx.org frontend library.
MIT License
109 stars 12 forks source link

docs: routing #36

Closed egil closed 2 months ago

egil commented 2 months ago

Done.

tanczosm commented 2 months ago

Is it possible to make template fragments routable by specifying a route?

egil commented 2 months ago

Is it possible to make template fragments routable by specifying a route?

Yes, add the @page or [HtmxRoute] to the component. However, then it's just a directly routable component and not a template fragment anymore.

A template fragment is a fragment of another page or component, it's not the full page or component that is directly routable. That's the idea behind "Locality of Behavior".

You have some content in a full page that you want to keep together with the other parts of the page, but it may also be a part that should be accessible during htmx targeted/swapping thing.

In the article https://htmx.org/essays/template-fragments/, they make the fragments addressable in a sense, because, I assume, they have an endpoint definition, where they inspect the incoming request, and then decide on a template and fragment to return, much like using Minimal Api endpoints in dotnet.

With the more declarative routing logic in Blazor and Htmxor, the decision of which parts or the whole of a component should render should naturally be more declarative, I think. Thus the whole idea of conditional components.