G
G
GeorgeKay2021-12-03 12:01:01
React
GeorgeKay, 2021-12-03 12:01:01

How to specify relative path for links in React?

There is such a code in it, the ejs template engine was used, I am now rewriting it to react, so how can I specify this path in the a tag?

<ul>
        {posts.length &&
          posts.forEach(({ id, title, createdAt, text, author }) => {
            <li>
              <article>
                <h2>
                  <a href="/posts/<%= id %>">{title}</a>
                </h2>
                <p>{text}</p>
                <div class="info">
                  <span>{createdAt.toLocaleDateString()}</span>
                  <span>{author}</span>
                </div>
                <button class="btn-delete" data-id={id} onClick={deletePost}>
                  <i class="fas fa-trash-alt" data-id={id}></i>
                </button>
              </article>
            </li>;
          })}
      </ul>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Anton, 2021-12-03
@GeorgeKay

I suspect you are asking about this: Reading about template strings
<a href={`/posts/${id}`}>{title}</a>

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question