36 lines
870 B
JavaScript
36 lines
870 B
JavaScript
|
|
import * as React from 'react';
|
||
|
|
import PropTypes from 'prop-types';
|
||
|
|
import { Link as RouterLink, MemoryRouter, StaticRouter } from 'react-router';
|
||
|
|
import Button from '@mui/material/Button';
|
||
|
|
|
||
|
|
const LinkBehavior = React.forwardRef((props, ref) => (
|
||
|
|
<RouterLink ref={ref} to="/" {...props} role={undefined} />
|
||
|
|
));
|
||
|
|
|
||
|
|
function Router(props) {
|
||
|
|
const { children } = props;
|
||
|
|
if (typeof window === 'undefined') {
|
||
|
|
return <StaticRouter location="/">{children}</StaticRouter>;
|
||
|
|
}
|
||
|
|
|
||
|
|
return <MemoryRouter>{children}</MemoryRouter>;
|
||
|
|
}
|
||
|
|
|
||
|
|
Router.propTypes = {
|
||
|
|
children: PropTypes.node,
|
||
|
|
};
|
||
|
|
|
||
|
|
export default function ButtonRouter() {
|
||
|
|
return (
|
||
|
|
<div>
|
||
|
|
<Router>
|
||
|
|
<Button component={RouterLink} to="/">
|
||
|
|
With prop forwarding
|
||
|
|
</Button>
|
||
|
|
<br />
|
||
|
|
<Button component={LinkBehavior}>With inlining</Button>
|
||
|
|
</Router>
|
||
|
|
</div>
|
||
|
|
);
|
||
|
|
}
|