Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

React-Router: How to retrieve the current route's parent?

How to retrieve the current route's parent? I need it in order to be able to navigate "up" in my app.

like image 806
FranBran Avatar asked Nov 09 '22 23:11

FranBran


1 Answers

In child component's render -

var currentPath = this.props.location.pathname,
parentPath = currentPath.substring(0, currentPath.lastIndexOf("/"));
return (<Link to={parentPath}>Up</Link>...);
like image 146
hazardous Avatar answered Nov 14 '22 21:11

hazardous