3 ms·
> there's no relative routes https://github.com/ReactTraining/react-router/issues/2172 https://github.com/ReactTraining/react-router/issues/2172 I've been mana
by sorahn 8y ago
> there's no relative routes https://github.com/ReactTraining/react-router/issues/2172 https://github.com/ReactTraining/react-router/issues/2172
I've been managing "relative" routes by just using `match.path` and `match.url` from the previous route. Works fine.
function Parent(props) {
return (
<>
<Link to='/child'>Child</Link>
<Route path='/child' component={Child}/>
</>
);
}
function Child({match}) {
return (
<>
<Link to={`${match.url}/grandchild`}>Grandchild</Link>
<Route path={`${match.path}/grandchild`} component={Grandchild} />
</>
)
}
- stickfigure 8y agoI also do this - 4 layers deep at times - and it works great. IMHO it's one of the more clever bits of react-router.
- sorahn 8y agoYup. My "top level routes" only have 3 paths, and everything goes from there. Thinking about routes just like components is really fantastic for react, and I don't miss having a giant central router even a little bit.