什么是自动指向不完整网址的角度方式?

时间:2013-03-29 22:32:06

标签: redirect angularjs

当我想要

http://www.koran-auf-deutsch.de/koran-deutsch/23-die-glaubigen-al-mominun/

然后输入

http://www.koran-auf-deutsch.de/koran-deutsch/23

我直接进入网址。我想得到类似的行为 在我的角度应用程序中,您将在哪里注入该功能?任何想法?

1 个答案:

答案 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'];