Ember Routing - Dynamic Segment

I am using Ember 3.18 and i have issue with dynamic segment. Here is my router.js

Router.map(function() {

    this.route('posts');

    this.route('post' , {path:"/post/:post_id"});

});

When I try to perform a transition from posts route (which contains all the posts) to post/:post_id (which displays the details of the particular post) using the following

{{#each this.data as |data|}}
   <LinkTo @route="dashboard.inbox-mail" @model={{data.id}}>
    <div class="card">
      <div>
        <p class="name">{{data.name}}</p>
      </div>
      <div>
        <p class="title">{{data.title}}</p>
        <p class="date">{{data.timestamp}}</p>
      </div>
    </div>
  </LinkTo>
  {{/each}}

it does not performs the transition to the post/:post_id. The data contains following attributes

id - string name - string title - string message - string timestamp - string

my goal is to pass the post id to post/:post_id and make a API call in the model hook of post/:post_id.

I was able to perform transition using the below code but the downside is that the beforemodel and model hook are not called. Passing the entire data as model results in not calling the model and beforemodel

<div>
{{#each this.data as |data|}}
   <LinkTo @route="dashboard.inbox-mail" @model={{data}}>
    <div class="card">
      <div>
        <p class="name">{{data.name}}</p>
      </div>
      <div>
        <p class="title">{{data.title}}</p>
        <p class="date">{{data.timestamp}}</p>
      </div>
    </div>
  </LinkTo>
  {{/each}}
</div>

Hi @Ruban_Thilak, it sounds like you have the right idea, there must be some small mistake that isn’t shown in this code.

Your router.js shows post route but your template shows dasboard.inbox-mail route. Maybe this is just a copy-paste problem on the forum and not in your app, but make sure you really have the route names the same.

As long as data.id is a string or number, it should work the way you want – the model hook will run, and receive the id in params.