AUR0810
Error Message
AUR0810: Invalid [else] usage, it should follow an [if]
Description
This error occurs during template linking when Aurelia encounters an element with an else custom attribute, but the immediately preceding element sibling in the DOM (after template compilation) does not have an if.bind attribute or another else attribute. The else attribute must directly follow an if or another else to form a conditional chain.
Cause
Incorrect Placement: The element with the
elseattribute is not placed immediately after the element with the correspondingif.bindorelseattribute in the HTML template. There might be other elements, comments (that aren't removed during compilation), or significant whitespace between them.Missing
if.bind: The preceding element, which was intended to be the start of the conditional block, is missing theif.bindattribute.Template Manipulation: Manual manipulation of the DOM or compiled template structure before or during linking might disrupt the expected
if/elsesequence.Syntax Error: A simple typo or syntax error in the template might lead to the
elsebeing misinterpreted or misplaced relative to theif.
Solution
Verify Placement: Ensure the element with the
elseattribute is the immediate sibling following the element withif.bindor a precedingelse. Remove any intervening elements, comments, or excessive whitespace that might interfere. Remember that Aurelia operates on the structure after template compilation, so whitespace handling by the browser or compiler can sometimes play a role, though typically direct element adjacency is required.Add
if.bind: If the preceding element is missingif.bind, add it with the appropriate condition.Check Template Structure: Review the HTML template carefully around the
if/elseblock for any structural issues or typos.
Example
<!-- Correct Structure -->
<div if.bind="condition">Show if true</div>
<div else>Show if false</div>
<!-- Also Correct (Chained else) -->
<div if.bind="status === 'loading'">Loading...</div>
<div else if.bind="status === 'error'">Error occurred</div>
<div else>Data: ${data}</div>
<!-- Incorrect: Intervening element -->
<div if.bind="condition">Show if true</div>
<p>Some other text</p> <!-- This <p> breaks the chain -->
<div else>Show if false</div> <!-- AUR0810 Error -->
<!-- Incorrect: Missing if.bind on the first div -->
<div>Show if true?</div> <!-- Missing if.bind -->
<div else>Show if false</div> <!-- AUR0810 Error -->
<!-- Incorrect: else not immediately following -->
<template>
<div if.bind="condition">Show if true</div>
</template>
<!-- Some other unrelated element or structure -->
<div else>Show if false</div> <!-- AUR0810 Error: 'else' is not linked to the 'if' -->Debugging Tips
Carefully inspect the HTML source template around the
ifandelseelements. Pay close attention to the direct sibling relationship.Use the browser's developer tools ("Inspect Element") to look at the DOM structure after Aurelia has processed the template. Verify that the element with
elsedirectly follows the element withif(or a previouselse) in the rendered DOM structure just before the error occurs (this might require stepping through the linking process or examining the structure just before the error is thrown).Temporarily remove the
elseblock and ensure theifblock works correctly on its own.Simplify the content within the
ifandelseblocks to basic text to rule out complex content interfering with the structure detection.
Last updated
Was this helpful?