0

Hi i have one little bit issue while routing the path using angular.js.I am explaining my code below.

app.js:

var GoFastoApp=angular.module('GofastoHome',['ngRoute']);
GoFastoApp.config(function($routeProvider) {
    $routeProvider
    .when('/',{
        templateUrl : 'view/home.html',
        controller  : 'homecontroller'
    })
    .when('/deptinfo',{
        templateUrl : 'view/info.html',
        controller  : 'infocontroller'
    })
    .when('/TimeTable',{
        templateUrl : 'view/time.html',
        controller  : 'timecontroller'
    })
    .when('/course',{
        templateUrl : 'view/course.html',
        controller  : 'coursecontroller'
    })
    .when('/subject',{
        templateUrl : 'view/subject.html',
        controller  : 'subjectcontroller'
    })
    .when('/hod',{
        templateUrl : 'view/hod.html',
        controller  : 'hodcontroller'
    })
    .when('/faculty',{
        templateUrl : 'view/faculty.html',
        controller  : 'facultycontroller'
    })
})

When i am typing the url oditek.in/Gofast/ on the address bar of browser the required page is coming but after getting the page the the address bar url is showing oditek.in/Gofast/#/ .Here i am getting the unwanted # with this url and need to remove this.Please help me to resolve this problem.

satya
  • 3,508
  • 11
  • 50
  • 130
  • Did you turn on html5 mode? – Bas Slagter Oct 01 '15 at 11:52
  • 1
    Have a look at this [answer](http://stackoverflow.com/questions/32757368/angular-new-router-remove-from-url/32758015#32758015) – Arkantos Oct 01 '15 at 11:53
  • Did you enable html5Mode and define `` as explained in that answer ? Are you still facing the issue ? What is the browser that you're testing this ? – Arkantos Oct 01 '15 at 11:55
  • @Arkantos : i am testing in google chrome. Can I write `$routeProvider.html5Mode(true);` in this file ? – satya Oct 01 '15 at 11:58
  • @Arkantos : i did as per that answer but it is throwing some error. – satya Oct 01 '15 at 12:05
  • Nope. `html5Mode` method is on $locationProvider only. What is the error that you see in your console ? – Arkantos Oct 01 '15 at 12:11
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/91094/discussion-between-satya-and-arkantos). – satya Oct 01 '15 at 12:11
  • This is how angularjs routing works by default. Be aware when you set html5 mode on you will remove this, you might want to edit your .htaccess, web.config, ... file to always point to your index.html Also, in browsers that don't support the html5 mode, it will fall back to using the # again. – Swimburger Oct 01 '15 at 13:12

1 Answers1

2

You need to enable html5Mode and also specify the <base> URL value in your markup like below.

app.js

GoFastoApp.config(function($routeProvider, $locationProvider) {

    $locationProvider.html5Mode({
      enabled: true,
      requireBase: true
    });

   // remaining router config goes here
});

Usually it's preferred to have <base> inside your <head>, but if you have CSS & JS files outside of <head>, then add it at the bottom of your HTML page, probably after all CSS and JS files, before closing the <body>, define the baseURI like below.

<base href="/Gofast/">
Arkantos
  • 6,530
  • 2
  • 16
  • 36