簡體   English   中英

我的router.js是否正確?

[英]Is my router.js is correct?

嗨,當我嘗試在瀏覽器中訪問到dashboard/posts/id/comments路線時,出現UnrecognizedUrl錯誤。 以下是我的router.js我想問一下我的路由器是否wrong或者有人可以告訴我正確的方法

this.route('dashboard', function() {
  this.route('posts', function() {
    this.route('show', { path: ':post_id' }, function() {
      this.route('comments', { path: ':post_id/comments'}, function() { });
    });
  });
});

但是,如果我將{{outlet}}放在資源文件app/pods/dashboard/posts/show/template.hbs它的確會顯示我放在app/pods/dashboard/posts/show/comments/template.hbs時,我改變了我的router.js

  this.route('dashboard', function() {
    this.route('posts', function() {
      this.route('show', { path: ':post_id' }, function() {
        this.route('comments');
      });
    });
  });

我的目標是我要在其他頁面上app/pods/dashboard/posts/show/comments/template.hbs ,該頁面在瀏覽器URL中應為dashboard/posts/id/comments

應該像

this.route('dashboard', function() {
  this.route('routeA', function() {
    this.route('childRouteA', { path: '/:childRouteA_id' }, function() {
      this.route('childRouteAb');
    });
  });
});

例如: 儀表板/ routeA / id / childRouteAb

如果childRouteAb是動態ID,則應類似於

this.route('dashboard', function() {
  this.route('routeA', function() {
    this.route('childRouteA', { path: '/:childRouteA_id' }, function() {
      this.route('childRouteAb', { path: '/:childRouteAb'});
    });
  });
});

例如: 儀表板/路線A / ID / ID2

如果需要url在id之前指定id的類型,則可以這樣做。

this.route('dashboard', function() {
  this.route('routeA', function() {
    this.route('childRouteA', { path: '/childRouteA/:childRouteA_id' }, function() {
      this.route('childRouteB', { path: '/childRouteB/:childRouteB_id'});
    });
  });
});

例如: 儀表板/ routeA / childRouteA / id1 / childRouteB / id2

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM