Skip to content

devbyray/angularjs-routing-setup

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Angular routing Setup

Project structure:

  • app
    • src
      • js
        • libs
          • angular.min.js
        • app.js -sass
        • sass-structure
    • index.html
  • gulpfile.js
  • package.json
  • readme.md

How to install

  1. run (sudo) npm install
  2. run gulp
  3. Then go to the browser and paste: "http://localhost:3000/".

How to start an AngularJS routing app

In this example I already did the setup. But the most important things to do is:

Before you start, checkout this repo first: How to start an AngularJS app

  1. Now include the ngRoute script in your html: ngRoute source
  2. Give your application a name, in the app.js (var ngRouteApp = angular.module("ngRouteApp", ['ngRoute']);) & html (<html ng-app="ngRouteApp">). Be carfull that the name inside the angular.module("appName") is the same as the name inside the html ng-app.
  3. Add a several html file in the "views" folder. Like home.html, about.html & contact.html.
  4. In the app.js we need to create a routeProvider, to let the routes show the right content:
    ngRouteApp.config(function($routeProvider, $locationProvider) {
    $routeProvider
    .when('/', {
    templateUrl: '../views/home.html'
    })
    .when('/home', {
    redirectTo: '/'
    })
    .when('/about', {
    templateUrl: '../views/about.html'
    })
    .when('/contact', {
    templateUrl: '../views/contact.html'
    })
    .otherwise({
    redirectTo: '/'
    });
    });
    
  5. Now add <ng-view></ng-view> to the place where the views content needs to be shown.
  6. Now if you add home after the url, you will go to the root. When adding about, you see the about content.

About

How to start an AngularJS routing app

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published