sssilver
sssilver

Reputation: 2859

Routing in subdirectory in Angular.js

Is it possible to develop an Angular.js application in a way that would be abstracted from the the web directory path in which it will be deployed?

I am trying to put an Angular.js app in a web server subdirectory http://example.com/myproject/, but the router redirects me to the web server root -- http://example.com.

Below is my Angular.js app:

var myproject = angular.module('myproject', []);

myproject.config(function($routeProvider, $locationProvider) {
  $routeProvider.
    when('/', {templateUrl: 'partials/index.html', controller: IndexCtrl}).
    otherwise({redirectTo: '/'});

  $locationProvider.html5Mode(true);
});



function IndexCtrl($scope, $location) {

}

Upvotes: 20

Views: 15003

Answers (1)

Ben Lesh
Ben Lesh

Reputation: 108471

Try setting a <base href="/sudirectory"/> in your <head></head>. That's what I needed to do to get mine working, IIRC

Word of caution: This will mess with any anchor tags that have href="#", as well as act as the root for image srcs and the like.

Upvotes: 25

Related Questions