2014-12-27 2 views
0

각도 JS으로 패주 있지만 HTTP 상태 404 오류나는 다음과 같은 코드로 패주 할 필요가 각도 JS에 초보자이야

웹 콘솔 공연이 메시지를 가져 오는 방법을

로컬 호스트 : 8080/testasd/때문에 addStudent 자원을로드하지 못했습니다 : 서버 (404)의 상태로 응답

var mainApp = angular.module("mainApp", ['ngRoute']); 

    mainApp.config(['$routeProvider', 
    function($routeProvider) { 
     $routeProvider. 
      when('/addStudent', { 
       templateUrl: 'AddStudent.html', 
       controller: 'AddStudentController' 
      }). 
      when('/viewStudents', { 
       templateUrl: 'ViewStudents.html', 
       controller: 'ViewStudentsController' 
      }). 
      otherwise({ 
       redirectTo: '/addStudent' 
      }); 
    }]); 

    mainApp.controller('AddStudentController', function($scope) { 
     $scope.message = "This page will be used to display add student form"; 
    }); 

    mainApp.controller('ViewStudentsController', function($scope) { 
     $scope.message = "This page will be used to display all the students"; 
    }); 
+0

당신이 그것을 로컬 호스트로 이동 하시겠습니까 파일이 웹 루트에 web.config라는 만들 : 8080/testasd/addStudent 또는 localhost : 8080/addStudent? –

답변

0

당신은 요구 된 모든 URL에 대한 index.html를 보내도록 웹 서버를 구성해야합니다 (찾을 수 없음). 이를 다시 쓰기 규칙이라고합니다. 웹 브라우저가 해당 URL에 대해 GET 요청을 발행하고 웹 서버가 해당 위치의 파일을 찾으려고하기 때문입니다. 다시 쓰기 규칙을 사용하면 요청을 가로 채어 다른 파일로 리디렉션 할 수 있습니다.

경로의 URL이 웹 서버에 없지만 AngularJS를로드해야합니다. 따라서 모든 요청에 ​​대해 index.html을 웹 루트에서 보냅니다. 여기서는 단일 페이지 앱을 만드는 것으로 가정합니다. 아파치 웹 루트에 .htaccess라는 파일을 생성 들어

IIS를 들어

<IfModule mod_rewrite.c> 
    RewriteEngine On 
    RewriteCond %{REQUEST_FILENAME} !-d 
    RewriteCond %{REQUEST_FILENAME} !-f 
    RewriteRule ^(.*)$ index.html [QSA,L] 
</IfModule> 

<?xml version="1.0" encoding="utf-8"?> 
<configuration> 
<system.webServer> 
    <rewrite> 
     <rules> 
      <clear /> 
      <rule name="angular" patternSyntax="Wildcard"> 
       <match url="*" /> 
       <conditions logicalGrouping="MatchAll" trackAllCaptures="false"> 
        <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" /> 
        <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" /> 
       </conditions> 
       <action type="Rewrite" url="index.html" /> 
      </rule> 
     </rules> 
    </rewrite> 
</system.webServer> 
</configuration> 
+0

웹 루트에서 .htaccess를 만들었지 만 작동하지 않았습니다. –

관련 문제