mirror of
https://github.com/jambonz/next-static-site.git
synced 2026-10-04 02:04:26 +00:00
Fix docs sidebar navi active states
This commit is contained in:
+2
-2
@@ -9,10 +9,10 @@ import { Button, Icon, useMobileMedia } from './jambonz-ui';
|
||||
|
||||
function NaviItem({obj}) {
|
||||
const router = useRouter();
|
||||
const regex = new RegExp( `^${obj.link}` );
|
||||
const regex = new RegExp(`^${obj.link}`);
|
||||
const classes = {
|
||||
navi__link: true,
|
||||
active: regex.test( router.asPath ),
|
||||
active: regex.test(router.asPath),
|
||||
};
|
||||
|
||||
return (
|
||||
|
||||
@@ -12,8 +12,10 @@ import { getData, getDocs, getDocsPaths } from '../../lib/data';
|
||||
|
||||
function Sidebar({data}) {
|
||||
const router = useRouter();
|
||||
const parsedTab = router.asPath.replace(/^\/docs\/|^\/+|\/+$/g, '').split('/').shift();
|
||||
const parsedPath = router.asPath.replace(/^\/+|\/+$/g, '').split('/').pop();
|
||||
const [active, setActive] = useState({
|
||||
[data.navi[0].path]: true,
|
||||
[parsedTab]: true,
|
||||
});
|
||||
|
||||
const handleToggle = (slug) => {
|
||||
@@ -55,7 +57,7 @@ function Sidebar({data}) {
|
||||
</div>
|
||||
<ul className={classNames(subClasses)}>
|
||||
{item.pages.map((page) => {
|
||||
const isActiveItem = (router.asPath.split('/').pop() === page.path);
|
||||
const isActiveItem = (parsedPath === page.path);
|
||||
const itemClasses = {
|
||||
'ms': true,
|
||||
'active': isActiveItem,
|
||||
|
||||
Reference in New Issue
Block a user