Sample template using Fable.Lit with routing with Elmish? #52
Replies: 1 comment 3 replies
-
There are some options out there, in general any javascript router should work fine lit while it is a small framework for web components, it is just another tool, you can pick up any other similar alternatives when it comes for part of your application. That being said I have a few options to offer
Vaadin router pairs nicely with Lit components (that means Fable.Lit as well) for both Navigo/Vaadin you have to basically create a subscription so you can hook up your main elmish view and switch pages accordingly [<AutoOpen>]
module Router =
open Navigo
// using navigo
let Router = Navigo("/", {| hash = true |})
module Home =
type State { page: Page }
type Msg =
| PageChange of Page
module Subs =
let PageChange _ =
let sub dispatch =
Router
.on("/", fun _ -> dispatch Home)
.on("/about", fun _ -> dispatch About)
// ...
// please note that resolve must be called at least once
// for the navigo router
.resolve()
|> ignore
Cmd.ofSub sub
let init = // ...
let update state msg =
match msg with
| PageChange page -> { state with page = page }, Cmd.none // or any other command as required
//...
let view state dispatch = //...
// somewhere else
open Home
Program.mkProgram init update view
|> Program.withLit "app-container"
|> Program.withSubscription Subs.PageChange
|> Program.run In any case, any agnostic solution should work fine with Lit/Fable.Lit as Lit isn't meant to lock you in the framework/tool rather enable you to use the platform and anything that works with it |
Beta Was this translation helpful? Give feedback.
-
Is there any template that I could look at on how to create a simple web app with routing? There are packages out there for React, but if I'm building pure Lit apps.. what routing libraries should I use? There is template such as https://github.com/JordanMarr/fable-lit-fullstack-template, and that uses grapnel library for routing. I'm not really sure how to connect the dots if I'm implementing Elmish with Lit with a routing library?
Of course I could use Feliz libraries, but like I mentioned I prefer to use pure lit components with basic routing rather than pulling React.
Beta Was this translation helpful? Give feedback.
All reactions