AdonisJS dynamics routing in html <a> not working

14 Views Asked by At

I'm currently working with AdonisJS but I've a problem with the dynamic routing. I made some research but I didn't find anything that solve my problem. My code :

BlogController.ts

...
async show ({params, view}: HttpContextContract) {
  const post = await Post.findOrFail(params.id)
  return view.render('blog/show', {
    post
  })
}

routes.ts

...
Route.get('/article/:id', 'BlogController.show').as('posts.show')

index.edge

...
@each(post in posts)
  <li>
    <div>
      <a href="{{ route('posts.show', {id: post.id}) }}"> // here's the error
        {{ post.title }}  
      </a>
    </div>
  </li>
@endeach
...

ERROR : E_CONNOT_MAKE_ROUTE_URL: "id" param is required to make URL for "/article/:id" route

I tried to write the link in clear text like <a href="article/0"> or <a href="article/{{post.id}}"> and it works but not with the routing.

0

There are 0 best solutions below