mirror of
https://github.com/movie-web/movie-web.git
synced 2024-12-28 03:41:52 +01:00
fix: when navigating to own pages, use useNavigate()
This commit is contained in:
parent
bada1d12cf
commit
f33bc583ea
@ -1,5 +1,6 @@
|
|||||||
import classNames from "classnames";
|
import classNames from "classnames";
|
||||||
import { ReactNode, useCallback } from "react";
|
import { ReactNode, useCallback } from "react";
|
||||||
|
import { useNavigate } from "react-router-dom";
|
||||||
|
|
||||||
import { Icon, Icons } from "@/components/Icon";
|
import { Icon, Icons } from "@/components/Icon";
|
||||||
import { Spinner } from "@/components/layout/Spinner";
|
import { Spinner } from "@/components/layout/Spinner";
|
||||||
@ -20,6 +21,7 @@ interface Props {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function Button(props: Props) {
|
export function Button(props: Props) {
|
||||||
|
const navigate = useNavigate();
|
||||||
const { onClick, href, loading } = props;
|
const { onClick, href, loading } = props;
|
||||||
const cb = useCallback(
|
const cb = useCallback(
|
||||||
(
|
(
|
||||||
@ -31,10 +33,14 @@ export function Button(props: Props) {
|
|||||||
if (loading) return;
|
if (loading) return;
|
||||||
if (href && !onClick) {
|
if (href && !onClick) {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
|
if (!href.includes("http")) {
|
||||||
|
navigate(href);
|
||||||
|
} else {
|
||||||
window.open(href, "_blank", "noreferrer");
|
window.open(href, "_blank", "noreferrer");
|
||||||
|
}
|
||||||
} else onClick?.(event);
|
} else onClick?.(event);
|
||||||
},
|
},
|
||||||
[onClick, href, loading],
|
[loading, href, onClick, navigate],
|
||||||
);
|
);
|
||||||
|
|
||||||
let colorClasses = "bg-white hover:bg-gray-200 text-black";
|
let colorClasses = "bg-white hover:bg-gray-200 text-black";
|
||||||
|
Loading…
Reference in New Issue
Block a user