Is my router.js is correct?

60 Views Asked by At

Hi I am getting an error of UnrecognizedUrl when I am trying to access my route on my browser to dashboard/posts/id/comments. Below is my router.js I would like to ask if my router is wrong or can someone please tell me the right approach

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

However if I put the {{outlet}} on my resource file app/pods/dashboard/posts/show/template.hbs it does show the content I put on my app/pods/dashboard/posts/show/comments/template.hbs when I changed my router.js to

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

My goal is I want to show the content of app/pods/dashboard/posts/show/comments/template.hbs on a different page which in the browser url should be dashboard/posts/id/comments

1

There are 1 best solutions below

2
On

It should be like

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

Ex: dashboard/routeA/id/childRouteAb

If childRouteAb is a dynamic id then, it should be like

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

Ex: dashboard/routeA/id/id2

If you need the url to specify the type of id before the id, you can do like this.

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

Ex: dashboard/routeA/childRouteA/id1/childRouteB/id2