我目前正在使用主干样板并在我的 MAMP 服务器 localhost 上运行它。我似乎无法让路由器工作
require([
// Global
"app",
// Libs
"jquery",
"backbone"
],
function(app, $, Backbone) {
// Defining the application router, you can attach sub routers here.
var Router = Backbone.Router.extend({
routes: {
"photo" : "getPhoto",
"*other" : "index"
},
index: function()
{
console.info('Index Function Working');
},
getPhoto: function()
{
console.log("You are trying to reach photo ");
}
});
// 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();
console.info('Here');
// Trigger the initial route and enable HTML5 History API support
Backbone.history.start({ pushState: true });
});
// 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 protocol
var href = $(this).attr("href");
var protocol = this.protocol + "//";
// Ensure the protocol is not part of URL, meaning it's 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);
}
});
});
它只是不断地达到索引功能。
我已将其放入我的网址“ http://localhost:8888/OutfitApp/#photo *”和“ http://localhost:8888/OutfitApp/photo ”
两者都不起作用。
我删除了
"*other" : "index"
没有任何东西进入我的控制台。
我很困惑我错过了什么??