Zaid-Ajaj / Feliz.Router

A router component for React and Elmish that is focused, powerful and extremely easy to use.
MIT License
78 stars 16 forks source link

pathMode not working #24

Closed olivercoad closed 4 years ago

olivercoad commented 4 years ago

Trying to get path mode working but router.onUrlChanged always passes the hash value.

Here is code to replicate on Feliz.Router 3.0.0

Router.currentPath() returns the expected value but router.onUrlChanged passes the hash mode segments to the callback funtion.

module App

open Elmish
open Elmish.React
open Feliz
open Feliz.Router

let parseUrl segments =
    let currentPath = Router.currentPath()
    sprintf "%A" currentPath, sprintf "%A" segments

type Msg =
    | UrlChanged of string * string

let init() = parseUrl <| Router.currentPath()

let update msg state =
    match msg with
    | UrlChanged (currentPath, currentUrl) -> currentPath, currentUrl

let render (currentPath: string, currentUrl: string) (dispatch: Msg -> unit) =
    React.router [
        router.pathMode
        router.onUrlChanged (parseUrl >> UrlChanged >> dispatch)
        router.children [
            Html.h1 "Router.currentPath(): "
            Html.p currentPath
            Html.h1 "segments from router.onUrlChanged: "
            Html.p currentUrl

            Html.a [
                prop.onClick (fun _ -> Router.navigatePath "/foo#bar")
                prop.children [ Html.p "change path" ]
            ]
        ]
    ]

#if DEBUG
printfn "Enabled HMR"
open Elmish.HMR
#endif

Program.mkSimple init update render
|> Program.withReactSynchronous "elmish-app"
|> Program.run
Zaid-Ajaj commented 4 years ago

Hi @olivercoad, thanks a lot for filing the issue! It seems like I haven't tested the new API properly, sorry about that. It should now be fixed as of v3.0.1 :smile: