Introduction
Welcome to the "Demonstrating Backbone.js" article series. This article demonstrates how to create and use Routers in Backbone.js. This article starts with the concept of Backbone.js and various components of it. Previous articles have provided an introduction to views and the implementation of views. You can get them from the following:
- Demonstrating Backbone.js: Implement View
- Demonstrating Backbone.js: Implement View Part 1
- Demonstrating Backbone.js: Implement View Part 2
- Demonstrating Backbone.js: Implement View Part 3
- Demonstrating Backbone.js: Implement View Part 4
- Demonstrating Backbone.js :Implement View Part 5
What a Router is
Backbone routers are used for routing our applications URL's when using hash tags (#). We can use render to navigate through our application.
First let's start creating our Views.
In the following snippet I have created two templates. The first template has the label of my first view and it has a link to go to the second view, so when we click on the link it should render the second view.
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="JavaScript.aspx.cs" Inherits="JavaScript.JavaScript" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script type="text/javascript" src="http://documentcloud.github.com/underscore/underscore-min.js"></script>
<script type="text/javascript" src="http://documentcloud.github.com/backbone/backbone-min.js"></script>
</head>
<body>
<script type="text/template" id="first_template">
<label>My 1st View</label>
<a href="#second">Go to 2nd View</a>
</script>
<script type="text/template" id="second_template">
<label>My 2nd View</label>
<a href="#first">Go to 1st View</a>
</script>
<div id="container">
</div>

Join the conversation! Your thoughts help the community grow.