当我想去的时候
http://www.koran-auf-deutsch.de/koran-deutsch/23-die-glaubigen-al-mominun/
然后输入
http://www.koran-auf-deutsch.de/koran-deutsch/23
我直接访问网址。我想在我的角度应用程序中获得类似的行为,你会在哪里注入该功能?有任何想法吗?
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'];