O'Reilly logo

Serverless Single Page Apps by Ben Rady

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required