Skip to content
Daryl Hedley edited this page Aug 13, 2014 · 5 revisions

The router in Origin has been built to be extendable through an events based system. The router has just two routes:

"": "handleIndex",
":module(/*location)(/*subLocation)(/*action)": "handleRoute"

handleIndex will check authentication and load the dashboard if authenticated. If not - then the login screen is loaded.

handleRoute will take in the module, location, subLocation and action - clears up the views, updates Origin.location object and triggers two events:

  • ('location:change', [Origin.location]) - Passes out the Origin.location object
  • ('router:' + module, [location, subLocation, action]) - Triggers a router event based upon the module argument from a route. Passes out location, subLocation and action.

createView(View, viewOptions, settings)

The Origin.router.createView() method takes in the view object, options to be attached to the view when constructed and a settings object. If the user is authenticated then the new view is created and appended to the '#app' DOM element. If the user is not authenticated then it loads the LoginView. If authenticate:false is passed in the settings object then the view will load regardless of the authentication check (useful when loading the forgot password or register views).

// Create a new DashboardView
Origin.router.createView(DashboardView, {model: new DashboardModel()});

// Create a forgot password view without authentication
Origin.router.createView(ForgotPasswordView, {model: Origin.sessionModel}, {authenticate: false});

Origin.location & Origin.previousLocation

  • Origin.location is an object containing the users current location
  • Origin.previousLocation is an object containing the users previous location
Clone this wiki locally