I am working on a project that has to support permalinks. A given url with no particular pattern can then redirect to different controllers.
For example let's consider a platform with two objects: users and posts with their respective url patterns /users/:id and /posts/:id.
For now how I am doing it (with ui-router) is by defining a controller for permalinks that catches unmatched urls.
app.config(function($stateProvider) {
$stateProvider
.state('userState', {
url: '/users/:id'
templateUrl: '/templates/users.html'
, controller: 'UserController'
})
.state('postState', {
url: '/posts/:id'
templateUrl: '/templates/posts.html'
, controller: 'PostController'
})
.state('permalink', {
url: '/:permalink'
, controller: 'PermalinkController'
})
;
});
In the permalink controller I can then query my server to know what type of object this permalink corresponds to.
app.controller('PermalinkController', function($scope, $state, $stateParams, Permalink) {
Permalink.get({ permalink : $stateParams.permalink }, function (result) {
// returns an "object_type" that can be either "users" or "posts"
}, function (err) {
});
});
Now where I am blocked is to redirect the data to the appropriate controller without changing the url. Is it possible to invoke this other controller directly from the permalink controller? If so, how?
Hope I'm not missing anything obvious!