2012-07-10 8 views
3

좋아,이게 뭔가 간단하다고 생각하지만, 나는 그것을보기 위해 어리 석다. 8888/릴, 내가 보일러와 함께 제공되는 예제 인덱스 페이지를 얻을 다음은 백본 상용구 방법백본 라우터가 보일러 플레이트를 사용하여 작동하지 않습니다.

require([ 
    "app", 

    // Libs 
    "jquery", 
    "backbone", 

    // Modules 
    "modules/example" 
], 

function(app, $, Backbone, Example) { 

    // Defining the application router, you can attach sub routers here. 
    var Router = Backbone.Router.extend({ 
    routes: { 
     "": "index", 
     "item" : 'item' 
    }, 

    index: function() 
    { 
     console.info('Index Function'); 
     var tutorial = new Example.Views.Tutorial(); 

     // Attach the tutorial to the DOM 
     tutorial.$el.appendTo("#main"); 

     // Render the tutorial. 
     tutorial.render(); 
    }, 

    item: function() 
    { 
     console.info('Item View'); 
    } 
    }); 

    // Treat the jQuery ready function as the entry point to the application. 
    // Inside this function, kick-off all initialization, everything up to this 
    // point should be definitions. 
    $(function() { 
    // Define your master router on the application namespace and trigger all 
    // navigation from this instance. 
    app.router = new Router(); 

    // Trigger the initial route and enable HTML5 History API support 
    Backbone.history.start({ pushState: true, root: '/reel' }); 
    }); 

    // All navigation that is relative should be passed through the navigate 
    // method, to be processed by the router. If the link has a data-bypass 
    // attribute, bypass the delegation completely. 
    $(document).on("click", "a:not([data-bypass])", function(evt) { 
    // Get the anchor href and protcol 
    var href = $(this).attr("href"); 
    var protocol = this.protocol + "//"; 

    // Ensure the protocol is not part of URL, meaning its relative. 
    if (href && href.slice(0, protocol.length) !== protocol && 
     href.indexOf("javascript:") !== 0) { 
     // Stop the default event to ensure the link will not cause a page 
     // refresh. 
     evt.preventDefault(); 

     // `Backbone.history.navigate` is sufficient for all Routers and will 
     // trigger the correct events. The Router's internal `navigate` method 
     // calls this anyways. 
     Backbone.history.navigate(href, true); 
    } 
    }); 

}); 

나는 MAMP 서버의이를 실행하고 나는 로컬 호스트를 입력 할 때를 이용하여 백본 내 코드입니다. 그러나 Localhost : 8888/reel/item 또는 Localhost : 8888/reel/# 항목을 입력하면 페이지를 찾을 수 없거나 색인 페이지로 돌아갑니다.

내 질문에 내가 뭘 잘못하고있다. htaccess를 사용해야합니까? 이 doesnt는 바르게 보인다. 백본을 사용하여이를 분류하는 방법이 있습니까? 죄송합니다. 이것이 정말 간단하다면, 그냥 내 머리를 그 주위에 가져 가라.

답변

1

문제는 pushState 플래그와 관련 될 수 있습니다. 당신이

$(function(){ 
     setTimeout(navMe, 2000); 
}); 
function navMe() { 
     backbone.navigate("item"); 
} 
이있는 경우

가 작동합니까 ... 요청에 그와

는 모든 방법을 서버로 이동하며 전체 URL을보고는 할 것입니다 무엇으로 응답

로드 후 2 초가 지나면 항목보기로 이동하며 요청이 서버로 가고 백본으로 이동하지 않기 때문에 해당 항목을 볼 수 있습니다.

관련 문제