From 4977c29040fd0363c8af3ba61614a8cd162e3443 Mon Sep 17 00:00:00 2001 From: DrMint Date: Mon, 28 Mar 2022 12:57:30 +0200 Subject: [PATCH] Fixed button not working if no href --- src/components/Button.tsx | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/src/components/Button.tsx b/src/components/Button.tsx index a968847..8da4382 100644 --- a/src/components/Button.tsx +++ b/src/components/Button.tsx @@ -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 = (
); - const result = props.href ? ( - + return ( +
{ + if (props.href || props.locale) + router.push(props.href ?? router.asPath, props.href, { + locale: props.locale, + }); + }} + > {button} - - ) : ( - button +
); - return result; }