Adding Routes

Our router is now capable of showing a second view, but that’s really all it does. The showView() function is hardcoded to just show the problem view. To fix this, we need to create something that lets our router associate hashes with view functions. Each of these associations is called a route, and we’re going to add one to our application now.

Our routes are going to be represented by a JavaScript object that acts as a lookup for the hash values we expect. This object will hold the associations between URL hash names and view functions. The view functions will return jQuery objects that contain the markup for our view. Right now, we only need one route, but we can add more views to our app by adding more entries to the routes ...

Get Serverless Single Page Apps now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.