mercredi 17 février 2021

Dynamic template arguments for an Ember component

I've run into a situation with a glimmer component that renders a LinkTo component within. The issue is that LinkTo treats the case where @model= and the case of omitting the @model argument as 2 different cases. This is because the default value for it is a special value of UNDEFINED. When this happens the component uses JS to make the transition i.e. the href is # and so you can't use browser commands like Open in new tab to open the resulting link. So I tried using inline ifs

    <LinkTo @route=
    ")}}
    ")}}
    >
    
    </LinkTo>

however, much as I expected this does not work. I've had to resort to having multiple if blocks like so:

    
      <LinkTo @route= @model= @query= @replace=>
        
      </LinkTo>
    
      <LinkTo @route= @models= @query= @replace=>
        
      </LinkTo>
    
      <LinkTo @route= @query= @replace=>
        
      </LinkTo>
    

This works, but is rather verbose and requires a lot of duplication. Is there a way to dynamically pass @model only when it is specified to the parent component?




Aucun commentaire:

Enregistrer un commentaire