Bolero
Bolero copied to clipboard
Routing when splitting a big application into smaller applications
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?
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
...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