当我想要
时http://www.koran-auf-deutsch.de/koran-deutsch/23-die-glaubigen-al-mominun/
然后输入
http://www.koran-auf-deutsch.de/koran-deutsch/23
我直接进入网址。我想得到类似的行为 在我的角度应用程序中,您将在哪里注入该功能?任何想法?
答案 0 :(得分:2)
angular.module('app', []).
config(['$routeProvider', function($routeProvider) {
$routeProvider.
when('/:id', {controller: RedirectCtrl}).
when('/:id/:title', {templateUrl: 'partials/post.html', controller: PostCtrl}).
otherwise({redirectTo: '/404'});
}]);
function RedirectCtrl($routeParam, $http) {
var post_id = $routeParams.id;
// get title by id
$http.get('/api_url_to_get_title_by_id').success(function (data) {
window.location = "/" + post_id + "/" + data.title;
});
}
RedirectCtrl.$inject = ['$routeParams', '$http'];