2017-03-15 17 views
-3

BACKBONE.JSルーティング障害

を更新しましたが、ルータが.Thisは私Router.jsあるindex.htmlをで機能を実行するためにやってみたかったすべてをしました。私はindex:function()を実行し、index.htmlに "Hello World"という文字列を表示したいと思います。これを行う目的は、router.jsをindex.htmlに接続することです。私がこれをやっていると、私は新しい機能で私のプロジェクトのために進歩します。

define([ 
    'jquery', 
    'underscore', 
    'backbone', 
    'handlebars', 
    'spin', 
    'app/models/LoginModel', 
    'app/collections/InformationCollection', 
    'app/collections/TravelCollection', 
    'app/collections/UserRegisterCollection', 
    'app/collections/UserSearchCollection', 
    'app/views/LoginView', 
    'app/views/UserRegisterView' 
], function ($, 
      _, 
      Backbone, 
      Handlebars, 
      Spinner, 
      Login, 
      Informations, 
      Travels, 
      UserRegister, 
      UserSearch, 
      LoginView, 
      UserRegisterViews 
) { 


    var Router = Backbone.Router.extend({ 

     routes: { 
      'search': 'search', 
      'login': 'login', 
      'travels': 'travels', 
      'user': 'user', 
      'menu': 'menu', 
      '':'index' 
     }, 

     index:function(){ 

      $(document.body).append("Hello World!.."); 
     }, 

への回答をありがとうそして、これは私のindex.html

<!DOCTYPE html> 
<html lang="en"> 
<head> 
    <meta charset="UTF-8"> 
    <title></title> 
</head> 
<body> 


</body> 
</html> 

私main.js

require.config({ 

    baseUrl: "resources", 
    waitSeconds: 100, 
    paths: { 
     'jquery': 'lib/jquery-1.9.1', 
     'bootstrap': 'lib/bootstrap', 
     'html5shiv': 'lib/html5shiv', 
     'spin': 'lib/spin', 
     'respond': 'lib/respond', 
     'underscore': 'lib/underscore', 
     'backbone': 'lib/backbone', 
     'handlebars': 'lib/handlebars-v3.0.3', 
     'template': 'app/templates' 
    }, 
    shim: { 
     html5shiv: { 
      deps: ['jquery'] 
     }, 
     respond: { 
      deps: ['jquery'] 
     }, 
     bootstrap: { 
      deps: ['jquery'] 
     }, 
     jquery: { 
      exports: '$' 
     }, 
     underscore: { 
      exports: '_' 
     }, 
     backbone: { 
      deps: ['jquery', 'underscore'], 
      exports: 'Backbone' 
     }, 
     handlebars: { 
      exports: "Handlebars" 
     } 
    }, 
    urlArgs: "bust=" + (new Date()).getTime() 
}); 

require([ 
    'jquery', 
    'bootstrap', 
    'html5shiv', 
    'respond', 
    'util', 
    'spin', 
    'underscore', 
    'backbone', 
    'handlebars', 
    'app/Router' 
], function ($, 
      $, 
      $, 
      $, 
      util, 
      Spinner, 
      _, 
      Backbone, 
      Handlebars, 
      Router) { 
    var Router = new Router(); 
    Backbone.history.start(); 
}); 

であると私はちょうど明確project.index.htmlをrunned "Hello World"のないページ。

答えて

0

あなたは、ルータをインスタンス化して、ドキュメントからBackbone.history.start()

var router = new Router(); 
Backbone.history.start(); 

を呼び出す必要があります:あなたのアプリケーションがそのルータのすべての作成が完了した後、Backbone.history.start()を呼び出してください、

ページのロード中またはBackbone.history.start({pushState: true})を入力して、最初のURLをルーティングします。