A Responsive Blogger Website, That Take my blog to the next level.

I am a Software Developer, Learning and experementing with .Net Technology and try to put my Learning altogether here.

We have all sections related to .Net Technology, like .Net-C#, Asp.Net, MVC, jQuery, AngularJs, Sharepoint. Find out more...

Following are the some of the Advantages of using this Web site :-

  • Get Update about latest in .Net world.
  • Collection of Useful, Frequently used .Net Solutions.
  • It’s beautiful on every screen size (try resizing your browser!)

AngularJS default route

Chandan Kumar
shared this article with you. 
At the moment the problem is that, if you try to navigate to a route that is not configured, you will see only the layout page without any partial template inject ed into it.
For example if you navigate to http://localhost:51983/ABC, since ABC is not a configured route you will see the layout page (index.html) as shown below.

AngularJS default route

You will also have this same problem if you navigate to the root of the site i.e http://localhost:51983. The reason angular is displaying the empty layout template in both these cases, is because it does not know what partial template to inject. We want angular to redirect to defau lt route if the user is trying to navigate to a route that is not configured.
How to configure the default route in Angular : Well that is straight forward. All you need is the following line in config() function in script.js file
    redirectTo: "/home"
With the above change the code in config() function should be as shown below.
.config(function ($routeProvider, $locationProvider) {
        .when("/home", {
            templateUrl: "Templates/home.html",
            controller: "homeController"
        .when("/courses", {
            templateUrl: "Templates/courses.html",
            controller: "coursesController"
        .when("/students", {
            templateUrl: "Templates/students.html",
            controller: "studentsController"
            redirectTo: "/home"

With this change if the user tries to navigate to a route that is not configured (http://localhost:51983/ABC) or just to the rooot URL (http://localhost:51983), the user will be automatically redirected to http://localhost:51983/home.

Inoreader is a light and fast RSS Reader. Follow us on Twitter and Facebook.