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

Always returns root on initial page load #20

Closed cmeeren closed 4 years ago

cmeeren commented 4 years ago

I noticed that this page has a link to https://cmeeren.github.io/Feliz.MaterialUI/#ecosystem, but the latter page only shows the root. (You can't even click "Ecosystem" in the menu - you have to navigate to another page, and then back to Ecosystem.)

Here is the code that runs the page. Seems correct to me. So is this a bug in Feliz.Router?

Zaid-Ajaj commented 4 years ago

Hi @cmeeren, I see the problem but I am not sure from first glance why it happens 😓 I can try to investigate it soon from your docs app

Zaid-Ajaj commented 4 years ago

I think I found the problem in this line

As of recent versions of Feliz.Router, you should provide the initial route in your init function like this:

let init () = {
  CurrentPath = Router.currentUrl()
  CustomThemeMode = None
}

This is because the onUrlChanged no longer trigger when the router component is mounted on application startup. Instead, the event is only triggered when the url actually changes after the router is mounted.

cmeeren commented 4 years ago

Excellent, thanks! Works now, published updated docs.