Last active
March 29, 2022 20:32
-
-
Save Exlord/e91a0f548ae890b6f257 to your computer and use it in GitHub Desktop.
Add a global Prefix to all routes in Angular 1.3 router
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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