ember.js 在Emberjs中路由器和路由有什么区别

tktrz96b  于 2022-11-05  发布在  其他
关注(0)|答案(2)|浏览(160)

在emberjs中,路由器和route有什么区别?如果可能的话,我想要一个可实现的解释

oknwwptz

oknwwptz1#

Router-成员应用程序将有一个Router,它管理路由之间的转换,并包含所有路由的Map。您可以按如下方式指定路由Map:

App.Router.map(function(){
  this.route('post', { path: '/post/:post_id' }, function() {
    this.route('edit');
    this.route('comments', { resetNamespace: true }, function() {
      this.route('new');
    });
  });
});
  • Router* 能够从中识别路由的结构及其接受参数。当您在浏览器ember router docs中导航到特定路径/url时,它会激活相应的 Route
    Route-对于每个 path/route,您将拥有Route对象,当您在浏览器中更改路径/url时,相应的Route将为该路径激活,并设置与该路径相关的所有内容(控制器、模板)(通常具有相同名称)。ember route docs

read more

46qrfjad

46qrfjad2#

这两者之间的实际区别在于,resource可以包含其他路由,而route不能。此外,当此.resource发现您有子路由时,它会自动创建索引路由。

App.Router.map(function() {
  this.resource('records', function() {
    // this.route('index') is created automatically in here
    this.route('new');
  });

  this.route('about');
});

虽然您可以始终使用此.resource并使其正常工作,但此.route会显式创建路由器叶状态,因此将为您的应用提供更精确和更高效的状态图。

相关问题