Give the following very basic Fable.Lit elmish application
module App
open Elmish
open Elmish.Navigation
open Lit
type Route =
| Contract
| Product
| Chart
type Model = {
Route_ : Route option }
type Msg = ...
let init route_ = {Route_ = route_}, Cmd.none
let update msg model = ...
let view (model:Model) dispatch =
match model.Route_ with
| None -> ...
| Some Contract -> ...
| Some Product -> ...
| Some Chart -> ...
open Lit.Elmish
open Elmish.UrlParser
let route = oneOf [
map Product (s "product")
map Contract (s "contract")
map Chart (s "chart") ]
let urlUpdate (route_: Option<Route>) model =
printf "urlUpdate"
model, Cmd.none
Program.mkProgram init update view
// |> Program.toNavigable (parseHash route) urlUpdate
|> Program.toNavigable (parsePath route) urlUpdate
|> Program.withLit "my-app"
|> Program.run
No problems With parseHash. Whenever I change the url in the browser url, for example 'http://host/#product' (including the # character) and press Enter, urlUpdate is called ('urlUpdate' gets printed in the dev tools console).
I would expect that with parsePath urlUpdate gets called with every change in the url bar. Instead, if the changed url doesn't contain '#', a page reload occurs and urlUpdate is never called.
Which is the correct way to capture any url change (either manual or programmatic)?