How to generate routing with URLs in Backbone.js

In many web applications, a user may want to show link-able, bookmark-able, and shareable URLs to meaningful locations within an app or a web page. The router updates the browser URL whenever there is any change in the web page. In short, the router detects any changes to the URL and changes the page content accordingly. For example, when you google something you are able to find a series of links pointing to a specific web page. Once you click on a page, the router makes sure it shows the web page you’ve clicked.

Code

For example, if you have three routes that are displayed, you will want to visualize the changes that will be made to the URL when you click on any one of the links. Then, open a notepad file and save it as data.html, for example. Next, introduce the code below as part of the HTML file.

By default, when you run data.html file in the browser, it shows:

file:///H:/data.html

Now, when you click on route1, the URL changes to:

file:///H:/data.html#/route1

When you click on route2, the URL changes to:

file:///H:/data.html#/route2

Similarly, when you click on route3, the URL changes to:

file:///H:/data.html#/route3

Free Resources

Copyright ©2026 Educative, Inc. All rights reserved