feat: init

This commit is contained in:
2025-09-05 18:20:53 +08:00
parent c9c9c8fa67
commit f46a851ee5
6 changed files with 54 additions and 8 deletions

View File

@@ -1,3 +1,3 @@
import useDocumentTitle from "./src/useDocumentTitle";
export { useDocumentTitle };
import useSafeNavigate from "./src/useSafeNavigate";
export { useDocumentTitle, useSafeNavigate };

View File

@@ -0,0 +1,23 @@
// hooks/useSafeNavigate.ts
import { useNavigate, NavigateOptions } from "react-router-dom";
const useSafeNavigate = () => {
const navigate = useNavigate();
return (path: string, options: NavigateOptions = {}) => {
const isBaidu = /baiduboxapp|baidubrowser|baidu/i.test(navigator.userAgent.toLowerCase());
if (isBaidu) {
const fullPath = path.startsWith("http") ? path : window.location.origin + path;
if (options.replace) {
window.location.replace(fullPath);
} else {
window.location.href = fullPath;
}
} else {
navigate(path, options);
}
};
};
export default useSafeNavigate;