fsbolero / Bolero

Bolero brings Blazor to F# developers with an easy to use Model-View-Update architecture, HTML combinators, hot reloaded templates, type-safe endpoints, advanced routing and remoting capabilities, and more.
https://fsbolero.io
Apache License 2.0
1.06k stars 53 forks source link

Routing when splitting a big application into smaller applications #158

Open AlexBoehm opened 4 years ago

AlexBoehm commented 4 years ago

When you split up a big application into multiple smaller applications as it is described in the Elmish Book for example, how would you do routing in such a case? Could you still use the inferred router?

I think it would be nice if each sub application could define it's own routing. However, the inferred router does not seem to support nested union types. How would you do this with Bolero?

NickDarvey commented 4 years ago

I just had the same question. It looks like you might be able to do nested union types?

https://github.com/fsbolero/Bolero/blob/fd1564c4f738d586f5669ca13bce477c8a07ee37/tests/Unit.Client/Routing.fs#L32

https://github.com/fsbolero/Bolero/blob/fd1564c4f738d586f5669ca13bce477c8a07ee37/tests/Unit.Client/Routing.fs#L51-L55

NickDarvey commented 4 years ago

...although having tried this myself there's some limitations. For example:

module Home =
  [<RequireQualifiedAccess>]
  type Page =
    | [<EndPoint "/w/{wid}/resources">]  Resources of wid : Workspaces.Id *  Resources.Page

module Resources =
  [<RequireQualifiedAccess>]
  type Page =
    | [<EndPoint "/">]      Index
    | [<EndPoint "/new">]   New
    | [<EndPoint "/{rid}">] Existing of sid : Resource.Id

This doesn't work and fails saying a field is missing in the path for 'Resources' 'Item 2' (i.e. the second field in Home.Page.Resource, a Resources.Page). If I understand correctly, the router resolves fields and pagemodels first (in parseEndPointCase) before merging endpoint cases (in parseUnion): https://github.com/fsbolero/Bolero/blob/fd1564c4f738d586f5669ca13bce477c8a07ee37/src/Bolero/Router.fs#L596-L605