0

I was going through one of the Ember tutorial on lynda.com and I saw that the instructor defined a dynamic route as:

this.route('bookmarks', function() {
this.route('new');

this.route('edit', {
  path: '/edit/:bookmark_id'
 });
});

Now if I go to browser and type: "http://localhost:4200/bookmarks/new" then I can see my new route is getting loaded and i can see the content there. But if I try: "http://localhost:4200/bookmarks/edit/1" then ember does not show anything unless I create a model by name bookmarks. Can anyone tell why a model is needed for dynamic routes to get executed?

Bhavya Bansal
  • 257
  • 1
  • 15
  • I guess it's because the implicit model hook of the route (supposing you didn't define it yet). You pass an id, so ember tries to get the fitting model. – Jeff Jun 21 '18 at 00:05
  • and what's wrong on simply defining the model?? – Jeff Jun 21 '18 at 00:06
  • @Jeff There is nothing wrong in defining the model but I want to understand the dynamics behind it. In first case ember does not need any model to be defined but in case of dynamic segments, aka, routes, ember needs a model to be defined. – Bhavya Bansal Jun 21 '18 at 02:30

1 Answers1

1

It's because you have :bookmark_id in route's path. It's called dynamic segment

Gennady Dogaev
  • 5,902
  • 1
  • 15
  • 23
  • one thing which I noticed few minutes back was if I return a model hook in route file and don't create a new model file, then also it works. So my guess is: in case of dynamic segments, ember needs model hook presence either from route.js or from model file for that route. – Bhavya Bansal Jun 21 '18 at 14:26
  • my gues would go further: Ember sets up a model on it's own and there it tries to use the model - which it can't find. – Jeff Jun 21 '18 at 16:11