Skip to content

How to make the home page layout like a sidebar + docs page? #4373

Answered by davestewart
davestewart asked this question in Q&A
Discussion options

You must be logged in to vote

OK, this is now the final solution...

I used a null in the sidebar config, which is cleaner:

sidebar: {
  '/': [null],
  ...
}

And I kept the router "hack" as it just means the logic to hide the sidebar is in one place (as above).

The router hook is now:

  enhanceApp({ app, router, siteData }) {
    router.onAfterRouteChanged = (to)  => {
      const sidebar = siteData.value.themeConfig?.sidebar[to]
      const noSidebar = sidebar?.length === 1 && sidebar[0] === null
      document.querySelector('#app')?.classList.toggle('noSidebar', noSidebar)
    }
  },

The CSS is now:

#app.noSidebar {
  --vp-sidebar-bg-color: none;

  #VPSidebarNav {
    display: none;
  }

  .VPNavBarTitle .title {
    

Replies: 2 comments 4 replies

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
4 replies
@brc-dd
Comment options

@davestewart
Comment options

@brc-dd
Comment options

@davestewart
Comment options

Answer selected by davestewart
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants