Skip to content
Bob Holt edited this page May 14, 2013 · 3 revisions

Router.js is a singleton object that inherits from Backbone.Router. The Keel Router ships with default page URL-handling code (an empty route and a "subdirectory" route invoke a goToPage() method).

This is one of the only instances of a major convention in Keel. The built-in goToPage() method expects there to be a module located in a specific location on the filesystem given a particular URL. For example, if our url looks like this: http://myApp.com/somepage/, then goToPage() expects there to be a View module located at app/pages/somepage/SomepagePage.js. The method will do the following:

  • Trigger the PageBeforeChange event
  • Use RequireJS to load the module
  • Invoke the View's constructor, render it, and place it in the DOM
  • Attach an event listener to the View, causing it to destroy itself on the next PageBeforeChange event
  • Trigger the PageChange event

This allows our single page app to redraw itself on each "page change." Whether this is the pattern you want to follow is up to you, but works for a standard default for us. Discussion welcome.

Clone this wiki locally