I have the following code and I need to insert a '/' in my href property.

<template for:each={assetData} for:item="item" for:index="indexvar">
   <tr class="slds-hint-parent" key={item.Id}>
         <a href={item.Id} target="_blank">{item.Account.Name}</a>

On aura component, I can easily do something like

<a href="{!'/' + item.Id}" target="_blank">{!item.Account.Name}</a>

But lwc does not allow me to do the same.


LWCs Templates are logicless and don`t support any Expressions anymore (see also here/here)

The engine doesn’t allow computed expressions

In your case you should either add a new computed property to your items in your assetData at runtime or create a child component (passing the id) which internally uses a getter or tracked variable which builds the link

  • 1
    I agree with "don't support any expressions" but they aren't logicless, i.e. <template if:true={value}></template> – interesting-name-here Jun 17 '20 at 14:10

Not the answer you're looking for? Browse other questions tagged or ask your own question.