Fixed button not working if no href
This commit is contained in:
parent
095ff6582d
commit
4977c29040
|
@ -1,4 +1,4 @@
|
||||||
import Link from "next/link";
|
import { useRouter } from "next/router";
|
||||||
import { MouseEventHandler } from "react";
|
import { MouseEventHandler } from "react";
|
||||||
|
|
||||||
type ButtonProps = {
|
type ButtonProps = {
|
||||||
|
@ -12,6 +12,8 @@ type ButtonProps = {
|
||||||
};
|
};
|
||||||
|
|
||||||
export default function Button(props: ButtonProps): JSX.Element {
|
export default function Button(props: ButtonProps): JSX.Element {
|
||||||
|
const router = useRouter();
|
||||||
|
|
||||||
const button = (
|
const button = (
|
||||||
<div
|
<div
|
||||||
id={props.id}
|
id={props.id}
|
||||||
|
@ -28,12 +30,16 @@ export default function Button(props: ButtonProps): JSX.Element {
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|
||||||
const result = props.href ? (
|
return (
|
||||||
<Link href={props.href} locale={props.locale} passHref>
|
<div
|
||||||
|
onClick={() => {
|
||||||
|
if (props.href || props.locale)
|
||||||
|
router.push(props.href ?? router.asPath, props.href, {
|
||||||
|
locale: props.locale,
|
||||||
|
});
|
||||||
|
}}
|
||||||
|
>
|
||||||
{button}
|
{button}
|
||||||
</Link>
|
</div>
|
||||||
) : (
|
|
||||||
button
|
|
||||||
);
|
);
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue