Using this code, the address i...">

Does rel-router support relative links?

I am at this URL:

/path1/path2

Then:

<Link to="path2/path3" />

Using this code, the address in the address bar changes to:

/path1/path2/path3

It seems that it worked: he went to the last one /and added a new path to it. But in fact, although it changes the URL in the address bar, navigation does not occur.

Does it look like links should have absolute urls?

+4
source share
4 answers

It is not supported, but you can easily create an absolute path:

<Link to={this.props.location.pathname + '/path3'}>
+8
source

According to the API documentation , links must be absolute:

to Link , ( ,

) pathname, ( ).

, , , , , .

react-router 2.x .

+4

. react-router-relative-links. , .

, :

{ RelativeLink } = require 'react-router-relative-links'
...
<RelativeLink to="./path3">My link text</RelativeLink>
+3

rel-router v4 . history " , ",

<Link to="two" />

history.push({ pathname: '..', search: 'foo=bar' });

URL- site/path/one site.com/path/two site.com/three?foo=bar.

NavLink , ( ). , .

, , , match ( router.route.match) to NavLink:

<NavLink to={`${match.url}/three`} />

.

+1

All Articles