fix: side effect of regex '/g'
This commit is contained in:
parent
6c9ab90843
commit
f858c91a12
@ -21,15 +21,9 @@ function Root() {
|
||||
const nav = useNavigation();
|
||||
const location = useLocation();
|
||||
|
||||
const [curTab, setCurTab] = useState("home");
|
||||
|
||||
useEffect(() => {
|
||||
setCurTab(
|
||||
NavConfigs.filter((c) => c.regex.test(location.pathname))
|
||||
.map((c) => c.key)
|
||||
.concat(["home"])[0],
|
||||
);
|
||||
}, [location]);
|
||||
const curTab = NavConfigs.filter((c) => c.regex.test(location.pathname))
|
||||
.map((c) => c.key)
|
||||
.concat("home")[0];
|
||||
|
||||
return (
|
||||
<>
|
||||
|
@ -26,13 +26,13 @@ const NavConfigs = [
|
||||
key: "home",
|
||||
to: "/home",
|
||||
label: "Home",
|
||||
regex: /^\/$|^\/home$/gi,
|
||||
regex: /^\/$|^\/home$/i,
|
||||
},
|
||||
{
|
||||
key: "problem",
|
||||
to: "/search/",
|
||||
label: "Problem",
|
||||
regex: /^\/+(problem|search)($|\/.*)/gi,
|
||||
regex: /^\/+(problem|search)($|\/.*)/i,
|
||||
},
|
||||
];
|
||||
|
||||
|
Reference in New Issue
Block a user