N
N
n1ksON2020-05-11 12:38:46
React
n1ksON, 2020-05-11 12:38:46

How to correctly add addresses to NavLink using JS?

Hello! Next question.
How to correctly insert a link using variables?
For example

const link = 'home'
<NavLink to={link}>

It works correctly, but if you need to make a subsection and get: example/home , then this doesn't work anymore.
const link = 'home'
<NavLink to='example/{link}'>

The final address is not exaple/home , but with unnecessary characters.

Thank you in advance.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
Vladimir, 2020-05-11
@HistoryART

const links = [{id: 1, url: '/example'}, {id: 2, url: '/example2'}];

links.map(link => (<NavLink to={link.url} key={link.id}>))

M
McBernar, 2020-05-11
@McBernar

NavLink to={'example/${link}'}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question