O'Reilly logo

Pro JavaScript for Web Apps by Adam Freeman

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

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

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