Bolero icon indicating copy to clipboard operation
Bolero copied to clipboard

Routing when splitting a big application into smaller applications

Open AlexBoehm opened this issue 4 years ago • 2 comments

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?

AlexBoehm avatar Jun 17 '20 11:06 AlexBoehm

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 avatar Jul 03 '20 04:07 NickDarvey

...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

NickDarvey avatar Jul 03 '20 06:07 NickDarvey