Answer the question
In order to leave comments, you need to log in
How to display a component on a new page?
Good afternoon!
I have something like layout. There is a Navbar and output routes.
app.js
function App() {
return (
<BrowserRouter>
<NavBar/>
<div className='content'>
<Routes>
<Route path='/movies/*' element={<Movies/>}/>
<Route path='/customers' element={<Customers/>}/>
<Route path='/rentals' element={<Rentals/>}/>
</Routes>
</div>
</BrowserRouter>
);
}
export default App;
renderCell = (item, column) => {
if (column.content) return column.content(item);
if (column.path === 'title') return <Link to={`/movies/${item._id}`}>{_.get(item, column.path)}</Link>
return _.get(item, column.path);
};
<Route path='/movies/' element={<Movies/>}>
<Route path=':id' element={<Movie/>}/>
</Route>
class TableBody extends Component {
renderCell = (item, column) => {
if (column.content) return column.content(item);
if (column.path === 'title') return <Link to={`/movies/${item._id}`}>{_.get(item, column.path)}</Link>
return _.get(item, column.path);
};
createKey = (item, column) => {
return item._id + (column.path || column.key);
};
render() {
const { data, columns } = this.props;
return (
<React.Fragment>
<tbody>
{ data.map(item => (
<tr key={ item._id }>
{columns.map(column => <td key={ this.createKey(item, column) }>{ this.renderCell(item, column) }</td>)}
</tr>
))}
</tbody>
<Routes>
<Route path=':id' element={<Movie/>}/>
</Routes>
</React.Fragment>
);
}
}
export default TableBody;
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question