JavaScript - Simple Route Configuration

Submitted by: 
Visitors have accessed this post 191 times.

In this tutorial we will create a Simple Route Configuration using AngularJS. AngularJS is a structural framework for dynamic web apps. It is a kind of template that extends HTML to a new level of coding techniques. It is mostly used by other well known site for creating a template.

Getting started:

First you will need to download & install the AngularJS here's the link

And download & install XAMPP or any local server that run PHP scripts. Here's the link for XAMPP server

Note: To make the angular-route.js work make sure you are running this application to any local server like xamp, etc..

Creating the Main Interface

This code contains the interface of the application. This code will render application and display the form. To do that just kindly write these block of code inside the text editor and save this as shown below.


  1. <!DOCTYPE html>
  2. <html ng-app="app">
  3. <head>
  4. <meta charset="UTF-8" name="viewport" content="width=device-width, initial-scale=1"/>
  5. <link href="css/bootstrap.css" rel="stylesheet" type="text/css"/>
  6. </head>
  7. <nav class="navbar navbar-default">
  8. <div class="container-fluid">
  9. <a class="navbar-brand" href="<a href="">Sourcecodester</a>
  10. " rel="nofollow">">Sourcecodester</a>
  11. </a> </div>
  12. </nav>
  13. <div class="col-md-3"></div>
  14. <div class="col-md-6 well">
  15. <h3 class="text-primary">JavaScript - Simple Route Configuration</h3>
  16. <hr style="border-top:1px dotted #ccc;"/>
  17. <ul class="nav nav-pills">
  18. <li><a href="#!">Home</a></li>
  19. <li><a href="#!about">About us</a></li>
  20. <li><a href="#!subject">Subject</a></li>
  21. </ul>
  23. <hr style="border-top:1px solid #ccc;"/>
  24. <ng-view></ng-view>
  25. </div>
  26. <script src="js/angular.js"></script>
  27. <script src="js/angular-route.js"></script>
  28. <script src="js/script.js"></script>
  29. </body>
  30. </html>


  1. <h1>Home</h1>


  1. <h1>Subject</h1>


  1. <h1>About us</h1>

Creating the Script

This code contains the main function of the application. This code will create a path that handle the web pages using angular-route.js. To that just kindly copy and write these block of codes inside the text editor, then save it as script.js.

  1. var app = angular.module('app', ['ngRoute']);
  3. app.config(function($routeProvider){
  4. $routeProvider
  5. .when('/', {
  6. templateUrl: 'home.html'
  7. })
  8. .when('/about', {
  9. templateUrl: 'about.html'
  10. })
  11. .when('/subject', {
  12. templateUrl: 'subject.html'
  13. })
  14. });

There you have it we successfully created a Simple Route Configuration using AngularJS. I hope that this very simple tutorial help you to what you are looking for. For more updates and tutorials just kindly visit this site. Enjoy Coding!!

Add new comment

Filtered HTML

  • Web page addresses and e-mail addresses turn into links automatically.
  • You may insert videos with [video:URL]
  • Allowed HTML tags: <a> <em> <strong> <cite> <blockquote> <code> <ul> <ol> <li> <dl> <dt> <dd> <table> <tr> <td> <th> <img> <h1> <h2> <h3> <iframe> [video]
  • You can enable syntax highlighting of source code with the following tags: <code>, <blockcode>, <asp>, <c>, <cpp>, <csharp>, <css>, <html4strict>, <java>, <javascript>, <mysql>, <php>, <python>, <sql>, <vb>, <vbnet>. The supported tag styles are: <foo>, [foo].
  • Lines and paragraphs break automatically.

Plain text

  • No HTML tags allowed.
  • Lines and paragraphs break automatically.
This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.