Merge pull request #20 from Accords-Library/develop

Fixed button not working if no href
This commit is contained in:
DrMint 2022-03-28 12:58:07 +02:00 committed by GitHub
commit 0049e53ce2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 13 additions and 7 deletions

View File

@ -1,4 +1,4 @@
import Link from "next/link";
import { useRouter } from "next/router";
import { MouseEventHandler } from "react";
type ButtonProps = {
@ -12,6 +12,8 @@ type ButtonProps = {
};
export default function Button(props: ButtonProps): JSX.Element {
const router = useRouter();
const button = (
<div
id={props.id}
@ -28,12 +30,16 @@ export default function Button(props: ButtonProps): JSX.Element {
</div>
);
const result = props.href ? (
<Link href={props.href} locale={props.locale} passHref>
return (
<div
onClick={() => {
if (props.href || props.locale)
router.push(props.href ?? router.asPath, props.href, {
locale: props.locale,
});
}}
>
{button}
</Link>
) : (
button
</div>
);
return result;
}