funcool / bide

A simple routing library for ClojureScript
BSD 2-Clause "Simplified" License
132 stars 20 forks source link

Remove doubled navigation on start #14

Closed pepe closed 6 years ago

pepe commented 7 years ago

With (apply on-navigate initial-loc) line the on-navigate callback is called twice when starting router. When removed, everything seems to work ok. Tested in Chrome, Safari, and Firefox on macOS.

Is there any special reason for reapplying I cannot see? It seems to me, that .replaceToken call on the line before removed, is enough to trigger it.

niwinz commented 7 years ago

Hmm, have you checked when url is exactly the same as the default one? I mean, when the user enters the page without a correct url and the router is initialized, the navigate will be triggered because the initial url is not exactly the default one. But if you follow with a refresh this will not trigger the navigate... (I think so).

This call there is for some purpose, right now i don't remember but without it there are some situatiuons where the first trigger is not executed. I need more check before accept MR.

In any case, thanks!

pepe commented 7 years ago

Thank you, I will investigate this case you are writing about. I actually have the same feeling, that the statement is there for some reason :-).

I'll get back with what I have found, hopefully, today.

YurySolovyov commented 6 years ago

I'm having this problem too, I've got event firing twice with same name. For routes like:

(def router
  (r/router [["/" :home]
             ["/landing" :landing]
             ["/auth-success" :auth-success]]))

and refreshing url like http://localhost:8911/#/landing, I have :landing nav happening 2 times

pepe commented 6 years ago

Oh, I totally forgot about this issue. I am actually using in production bide with this patch without any problems. It seems, that the call is actually redundant.

YurySolovyov commented 6 years ago

I'd be happy to have it landed and released in the next version.

niwinz commented 6 years ago

Released as 1.6.0. Thanks!