【发布时间】:2021-12-31 17:01:41
【问题描述】:
我想用我的 Link 组件(来自 react-router-dom)重定向到一个完全不同的 url,但它只是将这些字符添加到我当前的 url。 例如,如果我单击“http://localhost:3000/pin-detail/5HHceZ3LuAltt4AEKn2LYc”上的此链接
<Link to={`user-profile/${pinDetail.postedBy?._id}`} className='flex gap-2 m5-5 items-center bg-white dark:bg-darkg rounded-lg mt-2'>
<img src={pinDetail.postedBy?.image} alt="user-profile" className='w-8 h-8 rounded-full object-cover' />
<p className='font-semibold capitalize dark:text-white'>{pinDetail.postedBy?.userName}</p>
</Link>
它转到“http://localhost:3000/pin-detail/5HHceZ3LuAltt4AEKn2LYc/user-profile/104293279805278412025”。我希望链接将我重定向到“localhost:3000/user-profile/${pinDetail.postedBy?._id”。 我该怎么做?
【问题讨论】:
-
您使用的是亲戚
to。以/为前缀,例如to={'/user-profile...'} -
哦,谢谢。成功了!
标签: reactjs react-router