Sure. I found this working for me and wanted to share it with anyone who'd think it's useful. In link.js:
link.js
import NextLink from "next/link"; import MuiLink from "@mui/material/Link"; import MuiButton from "@mui/material/Button"; export default function Link({ type, href, children, ...props }) { if (type === "link" || !type) { return ( <NextLink href={href} passHref> <MuiLink {...props}>{children}</MuiLink> </NextLink> ); } else if (type === "button") { return ( <NextLink href={href} passHref> <MuiButton {...props}>{children}</MuiButton> </NextLink> ); } }
Then you can just use it as a utility components just like you would with Next and MUI's buttons:
import Link from "../path/to/link"; // Later... <Link type="button" href="/somewhere">Yay!</Link>
super!!!
I tried this but was not able to get it to work.
I added a links.js file and added your code.
then this import Link from "../path/to/link"; // Later... Yay!
but it doesn't work, I get the following error.
Any help please?!
Could you show a bit more code? Did you adjust the code to actually fit your project? Did you paste the correct code into your link component?
Thank you! Looks like I got it to work. I needed to install the mui library.
I just need to add styling b/c it just shows up as texts instead of a button.
Great, glad it worked out!
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Sure. I found this working for me and wanted to share it with anyone who'd think it's useful. In
link.js
:Then you can just use it as a utility components just like you would with Next and MUI's buttons:
super!!!
I tried this but was not able to get it to work.
I added a links.js file and added your code.
then this
import Link from "../path/to/link";
// Later...
Yay!
but it doesn't work, I get the following error.
Any help please?!
Could you show a bit more code? Did you adjust the code to actually fit your project? Did you paste the correct code into your link component?
Thank you! Looks like I got it to work. I needed to install the mui library.
I just need to add styling b/c it just shows up as texts instead of a button.
Great, glad it worked out!