The following messes with the onClick animation (the ListItem turns red):
<List> <a href="https://www.google.com"> <ListItem button> <ListItemText primary="Google" /> </ListItem> </a> </List>
While adding the link inside ListItem, only makes the transition work if ListItemText is clicked, which is not what I want. What is the correct way to add a link?
To add a link to a List with React Material UI, we can set the href prop of a ListItem component. We set the href prop of ListItem to a URL. And we set the component prop to 'a' to render the list item as a link. As a result, we should see a link rendered and it should go to https://www.google.com when we click on it.
js with Material-UI. Nextjs is a very popular server rendering library that so many people use for their development purposes. There are also so many UI libraries for server side rendering frameworks and Material UI is one of them. Material UI offers React components for faster and easier web development.
to use with "react-router-dom"
import { Link } from "react-router-dom"; <ListItem button component={Link} to="/design">
the example is based in this section: docs
The easiest way to accomplish this is to make the ListItem
a link by using the component
prop:
<List> <ListItem button component="a" href="https://www.google.com"> <ListItemText primary="Google" /> </ListItem> </List>
That way, the ListItem
will be an anchor tag linking to the desired place, but still receive the appropriate styling so that there won't be any visual changes.
The behavior of the component
prop is documented here. Note that the href
prop will be automatically passed to the anchor tag, as specified by the last line in the props documentation:
Any other properties supplied will be spread to the root element.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With