I'm trying to implement a route for the root scope like
/#/profile-1
/#/profile-2
/#/developer-name
Guess you get the idea. I'm using AngularJS 1.4 and UI Router 0.2.15.
My problem is now that I have this route, it's the last one in the order of my routes:
(function () {
'use strict';
angular
.module('bs3Prototype')
.config(routerConfig);
/** @ngInject */
function routerConfig($stateProvider, $urlRouterProvider) {
$stateProvider.
state('home', {
url: '/',
templateUrl: 'app/main/main.html',
controller: 'MainController',
controllerAs: 'main'
}).
state('profiles', {
url: '/profiles',
templateUrl: 'app/profiles/profiles_listing.html',
controller: 'ProfilesController',
controllerAs: 'profiles'
}).
state('search', {
url: '/search',
templateUrl: 'app/search/search.html',
controller: 'SearchController',
//controllerAs: 'search',
reloadOnSearch: false,
resolve: {
profileCategories: function(profileCategoriesService) {
return profileCategoriesService.index();
},
jobCategories: function(staticListsService) {
return staticListsService.getList('jobTypes');
},
agendaCategories: function(agendaCategoriesService) {
return agendaCategoriesService.index();
},
buildingTypes: function(buildingTypesService) {
return buildingTypesService.index();
}
}
}).
state('profile', {
url: '/:profileSlug',
templateUrl: 'app/profile/profile_view.html',
controller: 'ProfileController',
controllerAs: 'profile',
resolve: {
profile: function (profilesSerivce, $stateParams) {
console.log(profilesSerivce.getProfile($stateParams.profileSlug));
return profilesSerivce.getProfile($stateParams.profileSlug);
}
}
});
$urlRouterProvider.otherwise('/');
}
})();
In another view, my search results, I'm using this for the URL:
<a ui-sref="profile({profileSlug: result.slug})">Profile: {{result.profile_title.profile_title_default}} (ID: {{result.id}})</a>
This will correctly generate my slug route but when I click on it nothing happens and I have no idea why. Obviously it's able to resolve the object to an URL but not vice versa.
Second try:
I've read this page and tried it but no success either. At least the URL doesn't change and the slug URL stays but the controller is still not instantiated...
$urlMatcherFactoryProvider.type('profileSlug', {}, function(profilesService) {
var services = {
profile: profilesService
};
var checkedUrls = [];
return {
encode: function(item) {
console.log('encode');
console.log(item);
return item;
},
decode: function(item) {
console.log('decode');
console.log(item);
if (_.contains(checkedUrls, item)) {
return true;
}
return services.profile.getProfile(item).then(function(result) {
console.log(result);
checkedUrls.push(item);
return true;
});
},
is: function (item) {
console.log('is');
console.log(item);
return true;
}
}
});
The output of the console.log() calls is this:
index.route.js:36 is
index.route.js:37 architekturhalle
index.route.js:36 is
index.route.js:37 architekturhalle
index.route.js:36 is
index.route.js:37 architekturhalle
index.route.js:19 encode
index.route.js:20 architekturhalle
index.route.js:36 is
index.route.js:37 architekturhalle
I really don't understand why it is not calling decode as well.
I've only changed my profile route to this:
state('profile', {
url: '/{profileSlug:profileSlug}',
templateUrl: 'app/profile/profile_view.html',
//controller: 'ProfileController',
controller: function() { alert('TEST'); },
//controllerAs: 'profile',
resolve: {
profile: function (profilesSerivce, $stateParams) {
console.log(profilesSerivce.getProfile($stateParams.profileSlug));
return profilesSerivce.getProfile($stateParams.profileSlug);
}
}
});