0

Maybe I'm missing something, but I'm stuck with React Router Link and the path it's generating on the other location than '/'. To put it simple, when I'm on home ('/'), everything's okay, but when I am on the location (for example) http://somedomain.com/posts/newest and use Link component like this:

<Link to="/title-for-the-article">Link to the article</Link>

Raw HTML a tag after the render looks like this (which is not what I want)

<a href="/posts/title-for-the-article">Link to the article</a>

How to prevent that path '/posts/' from being attached to every Link component? I just want to use the exact path that I passed through the "to" attribute. Thanks.

1 Answers1

0

Use exact param it only returns the exact path that match the url.

<Route exact path="/posts/title-for-the-article" component={Component} />

<Link to="/posts/title-for-the-article">Link to the article</Link>

// Location descriptor path to in string
<Link to={{ pathname: '/posts/title-for-the-article' }}/>
user-9725874
  • 803
  • 7
  • 15