Surprisingly that it's been kind of hard to find in Google and in StackOverflow, I'm asking here what's the most efficient way on going up one level in React Router using <Link>
?
For example I land in this path: /subject/add
. Then I want to go to /subject
from /subject/add
.
This works:
<Link to={props.match.url.substring(0, props.match.url.lastIndexOf('/'))}>
Go up one level </Link>
Is it the best way to do it? (Note: history.goBack
could potentially kick out the user from the website if he arrived on a nested route as his landing page.