2013-03-21 84 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);