feat: init
This commit is contained in:
@@ -1,3 +1,3 @@
|
||||
import useDocumentTitle from "./src/useDocumentTitle";
|
||||
|
||||
export { useDocumentTitle };
|
||||
import useSafeNavigate from "./src/useSafeNavigate";
|
||||
export { useDocumentTitle, useSafeNavigate };
|
||||
|
||||
23
packages/hooks/src/useSafeNavigate.ts
Normal file
23
packages/hooks/src/useSafeNavigate.ts
Normal 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;
|
||||
Reference in New Issue
Block a user