C H A P T E R  4

Using URL Routing

In this chapter, I will show you how to add another server-side concept to your web app: URL routing. The idea behind URL routing is very simple: we associate JavaScript functions with internal URLs. An internal URL is one that is relative to the current document and contains a hash fragment. In fact, they are usually expressed as just the hash fragment on its own, such as #summary.

Under normal circumstances, when the user clicks a link that points to an internal URL, the browser will see whether there is an element in the document that has an id attribute value that matches the fragment and, if there is, scroll to make that element visible.

When we use URL routing, we respond to these navigation changes by ...

Get Pro JavaScript for Web Apps now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.