2

現在、バックボーンボイラープレートを使用しており、MAMPサーバーのローカルホストで実行しています。ルーターが機能しないようです

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);
    }
  });

});

インデックス関数をヒットし続けます。

これを自分のURL「http:// localhost:8888 / OutfitApp /#photo *」と「http:// localhost:8888 / OutfitApp/photo」に入れました

どちらも機能しません。

私は削除しました

"*other" : "index" 

私のコンソールには何も出てきません。

私は何が欠けているのか混乱していますか?

4

1 に答える 1

3

ドキュメントから:

アプリケーションがドメインのルートURL/から提供されていない場合は、オプションとして、ルートが実際にどこにあるかを履歴に必ず伝えてください:Backbone.history.start({pushState:true、root: "/ public / search / "})

それが問題でしょうか?

あなたの場合、試してみてください:

Backbone.history.start({pushState: true, root: "/OutfitApp/"})
于 2012-06-22T10:57:33.653 に答える