guides icon indicating copy to clipboard operation
guides copied to clipboard

Error routes don't need to be added to router.js

Open jonblack opened this issue 8 years ago • 5 comments

This is a follow-up to https://github.com/emberjs/ember.js/issues/5620.

The error substate documentation describes how error routes are matched. If you create an error route according to these rules (e.g. ember g route error) the error route fails with the message:

More context objects were passed than there are dynamic segments for the route: error

The solution is to remove the generated line from app/router.js:

Router.map(function() {
  this.route('error'); // <--- this should be removed
});

It would be great if the documentation could add this useful tidbit, and perhaps also explain why it's not needed.

jonblack avatar Mar 07 '17 14:03 jonblack

I was trying to find a related issue, and here it is: https://github.com/emberjs/ember.js/issues/14650#issuecomment-283387314. The error substate is different from having a route named error. It wasn't possible due to a bug in the router library, but it has been fixed. That is why in the route map examples present in that page you see neither a loading, nor an error route. Hm, not sure how to make the above more explicit, so suggestions are welcome.

locks avatar Mar 07 '17 16:03 locks

What's misleading (particularly for beginners) is the following line:

Ember will look for an error template or route in the following order

I've always considered a route to be something that extends Ember.Route and has an entry in router.js. It's interesting that you point out that the examples on that page don't actually show the error route in the route map, something which I didn't notice before.

How about something like this:

The error substate differs from having a route named error: it doesn't need an entry in the route map. If you generate your error route using ember-cli (e.g. ember g route error), make sure you remove the changes made to router.js.

I suppose the same sort of text is required for the loading substate as well?

jonblack avatar Mar 08 '17 08:03 jonblack

As you mentioned, this will apply to both error and loading, so I think the best approach is to explain this at the top of the document, before we dive into the individual substates.

Are you interested in opening a PR to address that? We can discuss details during the PR review process :)

locks avatar Mar 20 '17 10:03 locks

Yikes, this bit me hard, had no idea this was the reason based off the error message. It should really be explicit in the docs that you should not have an error entry in router.js.

skitterm avatar Sep 30 '17 01:09 skitterm

Well, the real issue is that the manually added error route doesn’t include a dynamic segment. I totally agree that we should handle this situation much better.

rwjblue avatar Sep 30 '17 03:09 rwjblue