app-router icon indicating copy to clipboard operation
app-router copied to clipboard

Fire 'template-not-found' event on route and router when template is null

Open nomego opened this issue 9 years ago • 3 comments

If the HTML import succeeds but the expected template can't be found (no template tag or wrong template ID), app router currently errors out with: Uncaught TypeError: Cannot use 'in' operator to search for 'createInstance' in null

This commit prevents that error and instead fires a template-not-found event.

nomego avatar Mar 20 '15 14:03 nomego

For something like this or the other import-error PR, would you ever be handling the event in production code or would this be more for debugging? If it's more for debugging I think we should throw an error with a custom message telling the developer what went wrong. https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error

erikringsmuth avatar Mar 22 '15 20:03 erikringsmuth

We currently use this in production code.

In our use case, in addition to any pre-registered routes, we register a route for whatever URL is being accessed dynamically in the state-change event, which causes app-router to try to fetch that view / template (ad-hoc routing). In any case we want something to react on, throwing an error can't be caught by the outer application in this case. It could be done in addition to the event, but it's nothing we would need. The import-error would be our client side 404 equivalent and we'd want to show a "this page doesn't exist". The template-not-found (some 4xx/5xx equivalent) event would not have any differentiating significance from import-error to the end user but we'd want the ability to register an automatic error report "behind the scenes". The events could however share the same event name and contain the specifics in the event information, if that fits the project better.

nomego avatar Mar 22 '15 21:03 nomego

@nomego Thanks for this.

The events could however share the same event name and contain the specifics in the event information, if that fits the project better.

I probably prefer this and re-use import-error. Would that cover your use-case?

jmalonzo avatar Jul 15 '16 09:07 jmalonzo