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

Example for routing doesnt route correctly? #66

Closed jkone27 closed 1 year ago

jkone27 commented 1 year ago

I am trying the routing example in the Feliz docs, but doesnt seem to route to pages when hitting different paths (/counter, /index and so on) i am using Feliz template V4..

    /// <summary>
    /// A React component that uses Feliz.Router
    /// to determine what to show based on the current URL
    /// </summary>
    [<ReactComponent>]
    static member Router() =

        printfn "current path %A" Router.currentPath()
        printfn "current url %A" Router.currentUrl()

        let (currentUrl, updateUrl) = React.useState(Router.currentUrl())

        React.router [
            router.onUrlChanged updateUrl
            router.children [
                do
                    printfn "routing to url %A" currentUrl
                match currentUrl with
                | [ ] -> Html.h1 "Index"
                | [ "hello" ] -> Components.HelloWorld()
                | [ "counter" ] -> Components.Counter()
                | _ -> Html.h1 "Not found"
            ]
        ]

and then main is the simple one given but replaced the router component in place of the other

root.render(Components.Router())
jkone27 commented 1 year ago

image image

Zaid-Ajaj commented 1 year ago

@jkone27 that is because by default, the router uses hash routing i.e. #/counter not, /counter. See Path routing if you want that instead

jkone27 commented 1 year ago

Thanks!