2017-02-15 61 views
0

當我從index.hbs執行{{#link-to "cars/category" "mini"}}時,一切正常。我轉換到cars/category - >templates/cars/category.hbslink-to在index.hbs中工作,但不在application.hbs中

但是,當我從application.hbs(用於導航)執行相同操作時,我切換到空白頁面,然後自動切換到父路線cars.index - >templates/cars/index.hbs

這可能有一些邏輯。如何從鏈接點擊application.hbs轉換到此路線?

(硬鏈接<a href="/cars/mini"工作正常,但我會失去了應用程序的狀態。)


routes/cars/category.js型號:

model(params) { 
    return this.store.findRecord('cars/category', params.category_id, {backgroundReload: false}); 
} 

route.js

this.route('cars',() => { 
    this.route('cars/category', { path: '/cars/:category_id' }); 
}); 

回答

1

有人建議,既然我轉移到所需的頁面,然後立即轉移到其母公司,一定有一些其他的過渡排隊。

經過進一步檢查,link-to確實在列表項的下拉菜單中,該列表項本身也是link-to

解決方法是將bubbles=false添加到內部link-to

其他答案在這裏懷疑使用的路線。但是,他們很好,並且像這樣設置是有原因的。例如。具有子路由的多個路由稱爲類別不能全部位於根目錄中。然而,這是我的錯,因爲他們沒有透露讓人走錯軌道的確切代碼,因爲他們可能會立即注意到實際問題。

下一次我將在我的代碼中更詳細。我道歉,謝謝你和我一起思考。

1

對於下面route.js

this.route('cars', function(){ 
    this.route('category', { path: '/:category_id' }); 
}); 

你可以做{{#link-to "cars.category" "mini"}},這將過渡到/cars/mini網址。

您不需要有cars/category。因爲它已經嵌套在cars路線中。 創建Sample Twiddle

爲了更好地理解路由看到AlexSpeller ember-diagonal

+0

無論是否有對路由器的建議更改,我都無法執行'{{#link-to「cars.category」「mini」}}';它會阻止應用程序啓動,拋出錯誤:_「未捕獲的錯誤:沒有名爲cars.category的路由。」_ – Redsandro

+0

@Redsandro用ember-twiddle更新了答案。 – kumkanillam

+0

你說得對。路線確實可以像這樣建模。 Upvoted因爲很好的例子。但是,這與問題無關。看到我自己的答案。 – Redsandro

1

爲灰燼2.11

你有沒有嘗試改變路由路徑,以點記號cars.category

樣本嵌套的路線,

Router.map(function() { 
    this.route('photos', function(){ 
    this.route('photo', { path: '/:photo_id' }, function(){ 
     this.route('comments'); 
     this.route('comment', { path: '/comments/:comment_id' }); 
    }); 
    }); 
}); 

合適的link-to幫手鍊接機智h動車鏈段,

{{#link-to 'photo.comment' 5 primaryComment}} 
    Main Comment for the Next Photo 
    {{/link-to}} 

你可以閱讀更多的,

https://guides.emberjs.com/v2.5.0/templates/links/#toc_example-for-multiple-segments

相關問題