Reputation: 9880
I have installed my Angular App in a location like this:
http://example.com/my-app
My App routing is like this:
var myApp = angular.module('myApp', ['ngRoute','ngAnimate', 'ui.bootstrap', 'angularFileUpload']);
myApp.config(['$routeProvider', function($routeProvider) {
$routeProvider
.when('/templates', {
controller: 'TemplatesController',
templateUrl: '/components/com_myApp/myApp/views/templates/template-list.html'
})
.when('/apps', {
controller: 'AppController',
templateUrl: '/components/com_myApp/myApp/views/apps/app-list.html'
})
.otherwise({
redirectTo: '/templates'
});
}]);
Now what happens is, when I go to http://example.com/my-app
, the url instead of showing http://example.com/my-app#/templates
it is showing as http://example.com/templates
It seems the otherwise
condition is basically removing the base directory my-app#
from the url. I have been scratching my head over this and after reading I also tried adding base url to head tag and tried changing the myApp.config
to this:
myApp.config(['$routeProvider', '$locationProvider', function($routeProvider, $locationProvider) {
$locationProvider.html5Mode(true);
....
}
But although the routing seems to work when using $locationProvider
like the above, the base url is still not showing the way I want it. The url is showing like this http://example.com/templates
without my-app
in the url path. I dont want Angular to remove the base path from the URL and I want the urls to show like this http://example.com/my-app/..xyz...
Why is Angular doing this?
Upvotes: 1
Views: 1909
Reputation: 729
This is happening because you've instructed Angular to not use hashbang URLs by specifying $locationProvider.html5Mode(true)
. Remove or otherwise comment out that code snippet and if you specified <base href="/">
in your root template file, remove or comment out that also and just use ngRoute
without those.
Upvotes: 2