Skip to content

Instantly share code, notes, and snippets.

@Exlord
Last active March 29, 2022 20:32
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Exlord/e91a0f548ae890b6f257 to your computer and use it in GitHub Desktop.
Save Exlord/e91a0f548ae890b6f257 to your computer and use it in GitHub Desktop.
Add a global Prefix to all routes in Angular 1.3 router
if (!Array.prototype.indexOf) {
Array.prototype.indexOf = function (needle) {
for (var i = 0; i < this.length; i++) {
if (this[i] === needle) {
return i;
}
}
return -1;
};
}
(function (angular) {
var origMethod = angular.module;
angular.module = function (name, reqs, configFn) {
var module = origMethod(name, reqs, configFn);
if (reqs.indexOf('ngRoute') == -1)
reqs.push('ngRoute');
///////////////////// override the browser service
module.config(['$provide', '$compileProvider', '$routeProvider', function ($provide, $compileProvider, $routeProvider) {
///// add route prefix to router when
var __when = $routeProvider.when;
$routeProvider.when = function (path, route) {
if (path.indexOf("MyRoutePrefix") == -1)
path = "MyRoutePrefix" + path;
__when.call($routeProvider, path, route);
};
}]);
return module;
};
})(angular);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment