I'm working on a react app where I'm implementing file system like uploading files and creating folders etc (little dropbox). I was reading about react router recursive paths from this link: https://reacttraining.com/react-router/web/example/recursive-paths There component is being rendered on same page. I want to do that recursive pattern but rather than rerendering on same page, I want to only render latest route data just like when you work with file systems on some server like cpanel or dropbox. Any help would be appreciated.
App.js
<Switch>
<Route
path={"/files/:title"} component={FolderDetail} />
</Switch>
FolderDetail.js
import React, { useState } from "react";
import { Switch, Route } from "react-router-dom";
import { Row, Col } from "reactstrap";
import UploadOptionsSidebar from "../components/Sidebar/UploadOptionsSidebar";
import BrowseFiles from "../components/BrowseFiles/BrowseFiles";
import CreateFolder from "../components/CreateFolder/CreateFolder";
import { AppContext } from "../components/Context/main";
const FolderDetail = ({ match, child }) => {
const { files } = React.useContext(AppContext);
const [createFolder, setCreateFolder] = useState(false);
const getFiles = () => {
return files.filter((file) => file.parent === match.params.title);
};
return (
<div>
<React.Fragment>
<h3>
Files >{" "}
<span className={"text-muted"}>{match.params.title}</span>{" "}
</h3>
<Row className={"mt-5 mx-0"}>
<Col md={"8"}>
<BrowseFiles files={getFiles()} />
</Col>
<Col md={"3"}>
<UploadOptionsSidebar
openCreateFolder={() => setCreateFolder(true)}
/>
</Col>
</Row>
<CreateFolder
open={createFolder}
parent={match.params.title}
toggle={() => setCreateFolder(false)}
/>
</React.Fragment>
<Switch>
<Route
path={`${match.url}/:title`}
render={() => <FolderDetail match={match} child={true} />}
/>
</Switch>
</div>
);
};
export default FolderDetail;