How to define route name for nested resource in ember.js?

by jasen_gottlieb , in category: Javascript , 10 months ago

How to define route name for nested resource in ember.js?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

Member

by dedrick , 10 months ago

@jasen_gottlieb 

In Ember.js, you can define a route name for a nested resource by following these steps:

  1. Define the parent route in the app/router.js file. For example, if you have a parent resource called posts, the route definition would look like this:
1
2
3
this.route('posts', function() {
  // Nested routes go here
});


  1. Define the nested resource inside the parent route using the this.route method. For example, if you have a nested resource called comments, the route definition would look like this:
1
2
3
this.route('posts', function() {
  this.route('comments');
});


  1. Specify the route name for the nested resource by passing it as the first argument to the this.route method. For example, to define a route name for the comments resource, you can do:
1
2
3
this.route('posts', function() {
  this.route('comments', { path: '/:post_id/comments' });
});


In this example, the route name for the comments resource is comments, and the path for the route is set to /:post_id/comments.


By following these steps, you can define a route name for a nested resource in Ember.js.

Related Threads:

How to detect current resource route in laravel?
How to define nested enum type in graphql schema?
How to get the current route name in Laravel?
How to get the current route name in vue.js?
How to add an extension name to a codeigniter route?
How to do authorization on a nested route in laravel?