Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to pass route parameter in a href using Alpine.js

I am using Alpine.js for the first time inside of a Laravel project and would like to add an a href tag to a component however I am unsure how to route the parameter correctly

<template x-for="(post, index) in posts" :key="index">
 <a x-bind:href="post.id">
  <p class="mt-2 block text-sm font-medium text-gray-900 truncate pointer-events-none">
<span x-text="post.text"></span>
  </p>
</a>
</template>

does redirect to

/id 

and passes the id but I need to go to the named route posts and expect

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

/posts/id

if I add

 <a x-bind:href="posts/post.id">

the result is a redirect with

/posts/NaN

>Solution :

You cn try this: <a x-bind:href="posts + '/' + post.id">

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading