2

Can Secretary dispatch routes based on a submitted browser url, the way many javascript routing frameworks work? I can't seem to find any examples of wiring this up.

For example, when you enter http://myapp.com/#/my/route in the browser's url, I'd like that to dispatch as though I had programatically entered (secretary/dispatch! "/my/route") in the repl.

Scott Klarenbach
  • 37,171
  • 15
  • 62
  • 91

1 Answers1

2

It can, but not by itself. The most common way of doing this is with Google Closure, as in the README.md example:

(let [h (History.)]
  (goog.events/listen h EventType/NAVIGATE #(secretary/dispatch! (.-token %)))
  (doto h (.setEnabled true)))

When you call setEnabled in the example above, the NAVIGATE event will automatically fire for the current location which will cause dispatch! to be invoked.

Derek Slager
  • 13,619
  • 3
  • 34
  • 34