2012-02-15 16 views
0

私はnode.js(サーバー)とbackbone.js(クライアント)アプリケーションを持っています - ページに私のバックボーンアプリケーションをロードして初期化することができます...そしてルータを初期化します。 "。*")は呼び出されません。私は手動でルータを初期化した後にインデックス関数を呼び出すことができますが、私はレール上でバックボーンアプリケーションを構築したときにそのステップを実行する必要はありません。ルートは処理されません

これはなぜ起こっているのか誰かが知りませんか? (のCoffeeScriptで)コードを追加

:(手動routeを使用して正規表現のルートを追加しない限り)

class NodeNetBackbone.Routers.RegistryPatients extends Backbone.Router 
    routes: 
    ''   : 'index' 
    '.*'  : 'index' 
    '/index' : 'index' 
    '/:id'  : 'show' 
    '/new'  : 'new' 
    '/:id/edit' : 'edit' 

    initialize: -> 
    console.log 'init the router' 
    @registry_patients = new NodeNetBackbone.Collections.RegistryPatients() 
    # TODO: Figure out why this isn't sticking... 
    @registry_patients.model = NodeNetBackbone.Models.RegistryPatient 
    # TODO: Try to only round trip once on initial load 
    # @registry_patients.reset($('#container_data').attr('data')) 
    @registry_patients.fetch() 

    # TODO: SSI - why are the routes not getting processed? 
    this.index() 

    index: -> 
    console.log 'made it to the route index' 
    view = new NodeNetBackbone.Views.RegistryPatients.Index(collection: @registry_patients) 
    # $('#container').html('<h1>Patients V3: (Backbone):</h1>') 
    $('#container').html(view.render().el) 
+2

は、あなたがあなたのルートを定義する方法のいくつかの例を示すことができますか? – loganfsmyth

+0

コード例がなくても何が修正できないのかわかりませんので、コードを入力してください – Sander

+0

まあ、私はちょっと慌てるつもりですが、デフォルトルートは ''*' 'ではありません。それは '' ''(空の文字列)だけです。 –

答えて

0

バックボーン経路は正規表現ではありません。 fine manualから:

ルートは、スラッシュの間に単一のURLコンポーネントを一致パラメータ部品、:paramを含むことができます。任意の数のURLコンポーネントに一致するスプラット部分*splatがあります。

[...] "file/*path"のルートは#file/nested/folder/file.txtと一致し、"nested/folder/file.txt"をアクションに渡します。

そして、我々はソース、we'll see thisチェックした場合:

// Backbone.Router 
// ------------------- 
//... 
// Cached regular expressions for matching named param parts and splatted 
// parts of route strings. 
var namedParam = /:\w+/g; 
var splatParam = /\*\w+/g; 

をだからあなたの'.*'ルートは唯一ではなく、あなたが期待していると「何を」に一致するよりも、リテラル'.*'と一致する必要があります。

routes: 
    ''   : 'index' 
    #... 
    '*path'  : 'index' 

the bottom of your route listであなたの*pathルートがあることを確認してください:

// Bind all defined routes to `Backbone.history`. We have to reverse the 
// order of the routes here to support behavior where the most general 
// routes can be defined at the bottom of the route map. 

オブジェクト内の要素の「注文」についてのこの仮定は、むしろ思わ

は、私はあなたがより多くのこのような何かをしたいと思います危険な、私にはわからないthere is no guaranteed order

プロパティーを列挙する仕組みと順序(第1のアルゴリズムのステップ6.a、第2のステップ7.a)は指定されていません。

私はあなたがあなたのinitialize方法で手動でデフォルト*pathルートを追加したほうが良いと思う:

class NodeNetBackbone.Routers.RegistryPatients extends Backbone.Router 
    routes: 
    ''   : 'index' 
    '/index' : 'index' 
    '/:id'  : 'show' 
    '/new'  : 'new' 
    '/:id/edit' : 'edit' 

    initialize: -> 
    console.log 'init the router' 
    @route '*path', 'index' 
    #... 
関連する問題