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 nav = useNavigation();
|
||||||
const location = useLocation();
|
const location = useLocation();
|
||||||
|
|
||||||
const [curTab, setCurTab] = useState("home");
|
const curTab = NavConfigs.filter((c) => c.regex.test(location.pathname))
|
||||||
|
.map((c) => c.key)
|
||||||
useEffect(() => {
|
.concat("home")[0];
|
||||||
setCurTab(
|
|
||||||
NavConfigs.filter((c) => c.regex.test(location.pathname))
|
|
||||||
.map((c) => c.key)
|
|
||||||
.concat(["home"])[0],
|
|
||||||
);
|
|
||||||
}, [location]);
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
|
@ -26,13 +26,13 @@ const NavConfigs = [
|
|||||||
key: "home",
|
key: "home",
|
||||||
to: "/home",
|
to: "/home",
|
||||||
label: "Home",
|
label: "Home",
|
||||||
regex: /^\/$|^\/home$/gi,
|
regex: /^\/$|^\/home$/i,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
key: "problem",
|
key: "problem",
|
||||||
to: "/search/",
|
to: "/search/",
|
||||||
label: "Problem",
|
label: "Problem",
|
||||||
regex: /^\/+(problem|search)($|\/.*)/gi,
|
regex: /^\/+(problem|search)($|\/.*)/i,
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user