vitepress icon indicating copy to clipboard operation
vitepress copied to clipboard

Highlight active sidebar item when child page is loaded

Open phazonoverload opened this issue 2 years ago • 5 comments

Is your feature request related to a problem? Please describe.

Not every page in my docs should be in the sidebar. For example having a top-level page "Learn to do X" and that page pointing to variants with different technologies.

If the sidebar has /guide and I visit /guide, then the sidebar item for the route is highlighted with an active state. If I visit /guide/subpage, it does not.

This makes it hard for users to know where they are on a website, and does not auto-expand the section they are in.

Describe the solution you'd like

Either behavior that child pages make the parent page active in the sidebar, or provided as an option.

Describe alternatives you've considered

No response

Additional context

No response

Validations

phazonoverload avatar Apr 19 '23 11:04 phazonoverload

Once again, briefly summarized. You have a page (.md file) which is also included in your sidebar. This page contains links to other specialized pages which should not be listed in the sidebar.

The problem Vitepress has is that it can't always assume that the project directory is structured the same way as the manually created sidebar.

A possible solution could be to also iniclude activeMatch for a sidebar item, like it is currently for the navigation item: activeMatch: '^/learn-to-do-x' or try to guess the current active sidebar page by checking the current full path against all paths for pages added in the sidebar.

MarkusKeck avatar Apr 20 '23 23:04 MarkusKeck

Yes exactly. Well summarised- thank you.

phazonoverload avatar Apr 21 '23 09:04 phazonoverload

I have the same scene requirement. It would be great if the sidebar could support configuring activeMatch.

Red-Asuka avatar Oct 11 '23 01:10 Red-Asuka

Yeah I think this will be a great addition.

DominusKelvin avatar Feb 05 '24 17:02 DominusKelvin

We will will also highly benefit from such a activeMatch field. For now, we had to implement some custom JS code that runs on every window scroll event and manually sets the active sidebar item

ashercoren avatar Apr 11 '24 06:04 ashercoren