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