I'm trying to use PathJS, and get the following error in the console:
Uncaught TypeError: Object #<Object> has no method 'default'
(anonymous function)
I'm using the following tutorial: http://mtrpcic.net/2011/02/fragment-uris-theyre-not-as-bad-as-you-think-really/
With the plugin: https://github.com/mtrpcic/pathjs
My app loads jQuery then the PathJS plugin, then this code in app.js:
$("a").live("click", function(event){
var href = $(this).attr("href");
if(href[0] == "/"){
event.preventDefault();
window.location.hash = "#!" + href;
}
});
Path.default(function(){
$.get(window.location.hash.replace("#!", ""), function(data){
$("#contents").html(data);
});
});
Path.listen();
Any id开发者_如何学JAVAeas why I'm getting the error?
Your Path.listen()
should be wrapped up like this:
$(document).ready(function() {
Path.listen();
)};
If you are already doing that ( it doesn't appear so from the code above, but you may have just not included that part ) then I would question your Path.default
code. I see nothing about a default path in the documentation. There is however, a Path.root
, but you still need to provide it a route. I'm wondering if that may have been removed from the code at some point, as I do see it mentioned on the tutorial you mentioned.
精彩评论