justinfagnani / route

A client + server routing library for Dart
BSD 3-Clause "New" or "Revised" License
114 stars 40 forks source link

Routing on page load #28

Closed nikgraf closed 11 years ago

nikgraf commented 11 years ago

A proposal to fix the issue of Browsers behave differently on page load. If you start listening with a router in Chrome this will fire a handler on page load. In Firefox it doesn't.

Browsers tend to handle the popstate event differently on page load. Chrome and Safari always emit a popstate event on page load, but Firefox doesn't. see https://developer.mozilla.org/en-US/docs/DOM/window.onpopstate

To create a consistent behavior I copied the concept of Backbone's routing. Backbone routes by default when you starting the history. see https://github.com/documentcloud/backbone/blob/master/backbone.js#L1417 We also could implement a silent option to prevent routing on app start.

Further Changes:

pavelgj commented 11 years ago

I totally suppor the idea, it's an important thing to fix. If I read correctly, you made the router stateful so that it remembers the last called handler and doesn't trigger the handler twice for the same URL, and in the listen() you invoke the handle() explicitly, so in some browsers it'd be called twice but that would be OK with the first change.

I'm probably fine with this approach, except I probably wouldn't want to merge it into the master branch because we're working on a new version and it would be much easier to fix this there as most of this is already done. Can you please open an issue instead?

nikgraf commented 11 years ago

For sure. I opened an issue. https://github.com/dart-lang/route/issues/32 If this new branch is getting more stable, i wouldn't mind implementing it by myself.

cheers Nik