2013-01-25 3 views
0

내 응용 프로그램에는 아래에 정의 된대로 3 개의 경로가 있습니다. 모든 것이 제대로 작동하지만 정의되지 않은 경로가 호출되면 빈 페이지가 표시됩니다. 내가 다음 URL http://example.com/page.php/#invalidRoute을 입력하면 같은, 내가 ...경로가 없으면 함수를 호출하십시오.

사전에 .... 어떤 경로가 발견되지 않으면 내가, 내 코드는 아래와 같습니다 "프로필"보기를로드 할

ProfileRouter = Backbone.Router.extend({ 
    initialize : function() {}, 
    routes : { 
     '' : 'profile', 
     'detailedProfile' : 'detailedProfile', 
     'moreReviews' : 'moreReviews', 
    }, 
    profile : function() { 
     /*Load a profile*/ 
    }, 
    detailedProfile : function() { 
     /*Load detail profile*/ 
    }, 
    moreReviews : function() { 
     /*Load more review*/ 
    } 
}); 

덕분에 빈 페이지를 가지고

답변

1

다음과 같이 할 수 있습니다. 마지막 경로는 다른 경로가 수행하지 못한 모든 경로와 일치합니다. 이 경우 경로 순서도 중요합니다.

routes : { 
    '' : 'profile', 
    'detailedProfile' : 'detailedProfile', 
    'moreReviews' : 'moreReviews', 
    '*invalidRoute' : 'profile' /* catch all route */ 
} 
+0

@dennis –