Alayode / chiru

A project to express Web development competency You can view the project live at :
0 stars 1 forks source link

Laying out the Routing of the site #1

Closed Alayode closed 9 years ago

Alayode commented 9 years ago

Before I can finish building the pages I am going to have to use Angular's router. Angular has a module you can add to your application and turn it into a Single Page Application. Today I will fix this issue by using

angular-route.js

The Router is not included in Angular's main code why I don't know at the moment but I would love to find out. This is good practice in declaring your dependencies in your app.

Alayode commented 9 years ago

What is $routeProvider and where does it come from?

The $routeProvider.when() method in the above code actually creates a route with the given configuration. And the three .when()'s are creating three different routes.

But in your $routeProvider.otherwise('/handler'), you are telling angular to go to a route called /handler if the user tries to navigate anywhere outside the configured routes.

The mistake you are doing here is, you did not define a route at /handler. So you need to first define that route and then use it in .otherwise(). This is an example of the angular-route being used....

myApp.config(function($routeProvider, $locationProvider) {
    $locationProvider.html5Mode(true);
    $routeProvider.
        when('/handler', { controller: 'handleCtrl', templateUrl: 'handler.html' }).
        when('/chat', { controller: 'MyController', templateUrl: 'chat.html' }).
        when('/login', { controller: 'loginCtrl', templateUrl: 'login.html' }).
        otherwise({ redirectTo: '/handler' });
});

I will use this type of layout for the project. I think i will close this and add this to the wiki.