2014-06-06 6 views
5

다음과 같이 ui-router의 위키에서 약간 수정 된 코드를 고려하십시오. 액세스하려고 할 때 파이썬 3의 SimpleHttpServer 실행

var myApp = angular.module('myApp',['ui.router']); 

myApp.config(function($stateProvider, $urlRouterProvider, $locationProvider) { 
    // for any unmatched url 
    $urlRouterProvider.otherwise("/state1"); 

    $locationProvider.html5Mode(true); 

    // now set up the states 
    $stateProvider 
     .state('state1', { 
      url: '/state1', 
      templateUrl: "partials/state1.html" 
     }) 
     .state('state1.list', { 
      url: "/list", 
      templateUrl: "partials/state1.list.html", 
      controller: function($scope) { 
       $scope.items = ["A", "List", "of", "Items"]; 
      } 
     }) 
     .state('state2', { 
      url: "/state2", 
      templateUrl: "partials/state2.list.html", 
      controller: function($scope) { 
       $scope.things = ["a", "set", "of", "things"]; 
      } 
     }) 
}); 

, 나는 404 error를 얻을 : http://localhost:8000/state1234324324.

왜이 question 당은 /state1 URL과 관련된 정의 state을 가지고 /state1로하지 $urlRouterProvider.otherwise("/state1"); 다시 직접 모든 알 수없는 경로 했습니까?

답변

9

"/ state123413"과 같은 URL을 사용하여 서버에 도달하면 404 응답을 직접 반환하기 때문에 (클라이언트 측 라우팅 없음)

당신이해야 할 일은 포괄 경로를 갖는 것입니다. 예를 들어 표현할 수 있음

app.get('/*', function(req, res){ 
    res.render('defaulttemplate') 
} 

이렇게하면 클라이언트 측에서 강제로 라우팅됩니다. 일반 서버가 catchall 라우트를 설정하려면 ui 라우터 faq을 참조하십시오.

+0

왜 ui-router에서 제대로 작동하지 않습니까? 그렇지 않으면 지금은 작동하지만, 그 수정을 추가 한 이후로 내 경로가 작동하지 않습니다 ... –