2013-03-21 83 views
1

我決定使用path.js作爲我的jQuery插件的後端/重載功能,它幾乎可以正常運行,但似乎不起作用。鏈接到插件:https://github.com/mtrpcic/pathjsjQuery插件的Path.js問題

頭:

<script type="text/javascript" src="jquery.js"></script> 
<script type="text/javascript" src="core.js"></script> 
<script type="text/javascript" src="path.js"></script> 
<script type="text/javascript" src="back.js"></script> 

導航:

<div id="leftnav"> 
     <p class="leftnavtext"> 
      <a class="navlinks" id="about2" href="#/about">ABOUT</a> <br> 
      <a class="navlinks" id="process2" href="#/process">PROCESS</a> <br> 
      <a class="navlinks" id="materials2" href="#/materials">MATERIALS</a> <br> 
      <a class="navlinks" id="pricing2" href="#/pricing">PRICING</a> 
     </p> 

AJAX Javascript代碼:

$(document).ready(function(){ 
    $("#about2").click(function(){ 
    $("#content").load("content.html #about"); 
}); 
    $("#process2").click(function(){ 
    $("#content").load("content.html #process"); 
}); 
    $("#materials2").click(function(){ 
    $("#content").load("content.html #materials"); 
}); 
    $("#pricing2").click(function(){ 
    $("#content").load("content.html #pricing"); 
}); 
    $("#pricing3").click(function(){ 
    $("#content").load("content.html #pricing"); 
}); 
    $("#infinite1").click(function(){ 
    $("#content").load("content.html #infinite"); 
}); 


}); 

Path.js代碼(在頭back.js ,path.js是插件。):

function notFound(){ 
      $("#content .content").html("404 Not Found"); 
      $("#content .content").addClass("Error"); 
     } 

     function setPageBackground(){ 
      $("#content .content").removeClass("Error"); 
     }   

     Path.map("#/about").to(function(){ 
      $("#content .content").html("About"); 
     }).enter(setPageBackground); 

     Path.map("#/process").to(function(){ 
      $("#content .content").html("Process"); 
     }).enter(setPageBackground); 

     Path.map("#/materials").to(function(){ 
      $("#content .content").html("Materials"); 
     }).enter(setPageBackground); 

     Path.map("#/pricing").to(function(){ 
      $("#content .content").html("Pricing"); 
     }).enter(setPageBackground); 


     Path.root("#/about"); 
     Path.rescue(notFound); 

     $(document).ready(function(){ 

      Path.listen(); 
}); 

任何人都可以看到我的錯在哪裏呢?

回答

1

如果您嘗試通過在瀏覽器地址欄中輸入url直接導航至/#/materialsaccording to the author PathJS目前不支持此功能,因爲它僅用於客戶端路由。

我在我的onload腳本中加入了Path.history.pushState({}, "", location.hash);