-
-
Notifications
You must be signed in to change notification settings - Fork 32.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[material-ui-nextjs] Add Link
integration component
#40265
Conversation
Netlify deploy previewBundle size report |
}} | ||
// below props are required for NextLink to work with MUI Link | ||
passHref | ||
legacyBehavior |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we should see if we can avoid this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think so based on Next.js docs.
@mnajdova @mj12albert in case you missed the notification, please review it. |
/** | ||
* Extra class name to apply to the link. | ||
*/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What we usually use for the className:
/** | |
* Extra class name to apply to the link. | |
*/ |
Did this mui/mui-x#11693 accordingly.
}} | ||
// below props are required for NextLink to work with MUI Link | ||
passHref | ||
legacyBehavior |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should update to the latest stable API, part of is:
legacyBehavior |
I don't see why it's needed, I would expect <MdLink component={NextLink}>
to work fine.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems to work without legacyBehavior
, e.g. https://github.com/mui/material-ui/pull/40661/files#diff-a6d4f073876950175d7c8a264331432489c8f9317e2a6f6b845248c0f7945314R25
For pages router, use the Link only from `@mui/material-nextjs/*-pagesRouter`: | ||
|
||
```js | ||
import { Link } from '@mui/material-nextjs/v13-pagesRouter'; // or `v14-pagesRouter` if you are using Next.js v14 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should also document how to use a Link with a Button.
import Button from '@mui/material/Button';
import NextLink from 'next/link';
<Button component={NextLink} href="/foo">
Actually, I don't know if this works (maybe types issue, maybe href prop conflict) but this is definitely an important use case.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also it should be possible to pass in NextLink
via a theme, right? Should we have that example as well?
:::warning | ||
Do not use the Link from <b>`@mui/material-nextjs/*-pagesRouter`</b> for App Router. | ||
::: | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can pass any props supported by both components to the Link. | ||
|
||
```js | ||
import { Link } from '@mui/material-nextjs/v13-appRouter'; // or `v14-appRouter` if you are using Next.js v14 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This creates a horizontal scrollbar, and I think better if set to be generic.
import { Link } from '@mui/material-nextjs/v13-appRouter'; // or `v14-appRouter` if you are using Next.js v14 | |
import { Link } from '@mui/material-nextjs/v13-appRouter'; | |
// or `v1X-appRouter` if you are using Next.js v1X |
The Link implementation we use on our docs got a bit simpler #40940, the gap with this one is reduced. |
I'll move this to v6. |
Preview: https://deploy-preview-40265--material-ui.netlify.app/material-ui/guides/nextjs/#link
Summary
Added Link for App Router and Pages Router (Both routers have different import for
useRouter
, so the split is required).Usage:
Related to #30858