Some checks failed
No response / noResponse (push) Has been cancelled
CI / Continuous releases (push) Has been cancelled
CI / test-dev (macos-latest) (push) Has been cancelled
CI / test-dev (ubuntu-latest) (push) Has been cancelled
CI / test-dev (windows-latest) (push) Has been cancelled
Maintenance / main (push) Has been cancelled
Scorecards supply-chain security / Scorecards analysis (push) Has been cancelled
CodeQL / Analyze (push) Has been cancelled
36 lines
885 B
TypeScript
36 lines
885 B
TypeScript
import * as React from 'react';
|
|
import {
|
|
Link as RouterLink,
|
|
LinkProps as RouterLinkProps,
|
|
MemoryRouter,
|
|
StaticRouter,
|
|
} from 'react-router';
|
|
import Button from '@mui/material/Button';
|
|
|
|
const LinkBehavior = React.forwardRef<any, Omit<RouterLinkProps, 'to'>>(
|
|
(props, ref) => <RouterLink ref={ref} to="/" {...props} role={undefined} />,
|
|
);
|
|
|
|
function Router(props: { children?: React.ReactNode }) {
|
|
const { children } = props;
|
|
if (typeof window === 'undefined') {
|
|
return <StaticRouter location="/">{children}</StaticRouter>;
|
|
}
|
|
|
|
return <MemoryRouter>{children}</MemoryRouter>;
|
|
}
|
|
|
|
export default function ButtonRouter() {
|
|
return (
|
|
<div>
|
|
<Router>
|
|
<Button component={RouterLink} to="/">
|
|
With prop forwarding
|
|
</Button>
|
|
<br />
|
|
<Button component={LinkBehavior}>With inlining</Button>
|
|
</Router>
|
|
</div>
|
|
);
|
|
}
|