I ran into the same problem that you are describing. I had hardcoded URLs in my application, and changing something was a nightmare. So I decided to come up with a good solution. And that’s what I finally decided. It may not be perfect, but so far I have not had any problems. PS. My application is huge, so there are many tracking URLs.
.constant('RoutePaths', {
login: {
login: '/login',
eula: '/login/eula',
noSubscription: '/no-subscription',
myAccount: '/my-account',
createAccount: '/my-account/create',
createAccountFromXID: '/my-account/update',
...
},
conreg: {
compInfo: '/bronze/companyInfo',
serviceArea: '/bronze/serviceArea',
licenses: '/bronze/licenses',
insuranceBonds: '/bronze/insuranceAndBonds',
certifiedReviews: '/silver/certifiedReviews',
certifications: '/silver/certifications',
yearsAndBBB: '/silver/yearsAndBBB',
...
},
....
}
Since I declared this object RoutePathsas constant, now I can use it in my application configin combination with the built-in $routeProvideras such:
app.config(['$routeProvider','RoutePaths', function($routeProvider, RoutePaths){
var login = RoutePaths.login;
$routeProvider
.when(login.login, {templateUrl: '../partials/login/login.html', controller: 'LoginCtrl'})
.when(login.eula, {templateUrl: '../partials/login/eula.html', controller: 'EulaCtrl'})
.when(login.myAccount, {templateUrl: '../partials/login/account.html', controller: 'AccountCtrl'})
...
}]);
And you can introduce the same dependency RoutePathsin any controllers, services, factories, filters, etc. that you need:
.controller('LoginCtrl', ['$scope','RoutePaths', function($scope, RoutePaths){
$scope.paths = RoutePaths.login;
...
}]);
And in your views, you can get attached to these paths using:
<a ng-href="{{paths.myAccount}}">My Account</a>
, , RoutePaths, . . - ?