2016-06-02 2 views
0

그래서 예를 들어 "http://www.test.com/serie/2"으로 리디렉션하여 serie의 정보 페이지로 이동하려고합니다.AngularJS를 사용하는 url 매개 변수가있는 페이지로 리디렉션 할 때

각도 라우팅을 사용하고 이전에 페이지를 다시로드 할 때 404 문제가 발생했습니다. 이것은 이제 작동하는 것처럼 보이지만 이제 세리 페이지로 리디렉션됩니다. 지금까지 제 코드가 있습니다.

홈보기 :

<div class="col col-md-10"> 
    <div class="col col-md-3" ng-repeat="serie in series | limitTo: 10"> 
     <serie-card 
      id="serie.id" 
      name="serie.name" 
      genres="serie.genres" 
      img="serie.image.medium" 
      lang="serie.language" 
      rating="serie.rating" 
      status="serie.status" 
      ng-click="openSerie(serie)"> 
     </serie-card> 
    </div> 
</div> 

세리에 카드 지시어 컨트롤러 :

app.controller('serieCardController', ['$scope', '$location', function($scope, $location){ 
    $scope.openSerie = function(id){ 
     var url = rootUrl+"/serie/" + id; 
     window.location = url; 
    } 
}]); 

내 app.js는 파일

app.config(['$routeProvider', '$locationProvider', 
    function($routeProvider, $locationProvider) { 
      $routeProvider. 
      when('/home', { 
       templateUrl: 'templates/home.php', 
       controller: 'homeController' 
      }). 
      when('/serie/:id',{ 
       templateUrl: 'templates/serie.php', 
       controller: 'serieInfoController' 
      }). 
      when('/login',{ 
       templateUrl: 'templates/login.php', 
       controller: 'loginController' 
      }). 
      otherwise({ 
       redirectTo: '/home' 
      }); 

      $locationProvider.html5Mode(true); 
}]); 

도움이된다면 나도 몰라 아무것도 .htaccess를 추가하여 URL 페이지 확장을 제거했습니다.

RewriteEngine On 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteRule ^([^\.]+)$ $1.php [NC,L] 

ErrorDocument 404 /error.php 

다른 곳에서는 답변을 찾을 수 없기 때문에 누군가가이 문제를 해결할 수 있기를 바랍니다.

답변

1

컨트롤러의 ID가 예상 되나 에있는 전체 serie 개체를 전달했습니다. 아마 두 개의 경로가 동일한 기본 경로에 있기 때문에보다 효율적으로 사용 $location을 완료 새로운 경로에 위치를 라우팅

ng-click="openSerie(serie.id)" 

대안에 그 변경해야합니다.

변경 window.location = url에서 $location.path("/serie/" + id)으로 변경하십시오.

+0

세리에/id 문제가 id뿐만 아니라 시도되었음을 확인했습니다. 또한 $ location.path를 사용하려고했지만 "$ location.path는 함수가 아닙니다."오류가 발생하고 $ 위치가 주입되었습니다. –

+0

'window.location'이 예상대로 작동합니까? – Sajal

+0

예, "www.test.com/serie/1"과 같은 URL로 리디렉션되지만 404로 응답합니다. –

관련 문제