Nested Routing Behavior for Ember.js

强颜欢笑 提交于 2019-12-03 21:49:45

You need to remove the dot notation for the nested routes. Use just artist instead of artists.artist.

Your corresponding router would be,

App.Router.map(function() {
  this.resource('profile');
  this.resource('artists', function() {
    this.resource('artist', { path: ':artist_id'}, function() {
      this.resource('tracks', function() {
        this.resource('playing', { path: ':track_id' });
      })
    });
  });
});

You can use App.Router.router.recognizer.names to get a list of routes being mapped in the Router.

This will give you the following URLs, routes and controllers.

  • /profile - ProfileRoute - ProfileController
  • /artists - ArtistsRoute - ArtistsController
  • /artists/1 - ArtistRoute - ArtistController
  • /artists/1/tracks - TracksRoute - TracksController
  • /artists/1/tracks/1 - PlayingRoute - PlayingController

Also note, each resource that has a nested resource also gets an implicit index route. Eg:- ArtistsIndexRoute, ArtistIndexRoute, TracksIndexRoute, but not PlayingIndexRoute because it has no nested routes.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!