const pages = ['home', 'menu', 'reservation'];
<Box sx={{ flexGrow: 1, display: { xs: 'none', md: 'flex' } }}>
{pages.map((page) => (
<Link component={Link} to='/'>Home</Link>
))}
</Box>
I tried watching one or two videos on how to use Routing in MUI, yet I was unable to find a solution to this. Tried implementing the examples from Routing Libraries from MUI and yet I was unable to get it. Is there a simpler way of getting it done? I have updated my routes and route in App.tsx.
2
Answers
You can use react router dom package 6 ..
here an example:
[Github example][1]
it has many methods to navigate, like “link to” and useNavigate
If I’m understanding your question correctly you are asking how to work with the
Link
component from@mui/core
and theLink
component fromreact-router-dom
. You want to render MUI links using the RRD link as the actual rendered UI component.Import and alias one of the
Link
components, typically the "inner" component. I suggest also updating thepages
array to hold objects that have both the link target path and the label you would like to display for it. Don’t forget to assign a React key to each mapped JSX element!Example: