Skip to content

Docs index page and navbar highlighting #1941

Closed

Description

@binarylogic

🐛 Bug Report

Note, this is for V2.

Currently, the themeConfig.navbar.links array requires that the "Docs" refer to an individual document. While this works there are 2 problems:

  1. Users navigating to just /docs get a 404.
  2. The "Docs" navbar item does not remain highlighted if the user navigates around to other pages with in the Docs section.

Have you read the Contributing Guidelines on issues?

Yes

To Reproduce

(Write your steps here:)

  1. Go here: https://v2.docusaurus.io/docs/
  2. Notice when you change pages the "Docs" navbar item is not "active". Ex: https://v2.docusaurus.io/docs/contributing

Expected behavior

  1. /docs should render docs/index.md or redirect to a specificed document.
  2. The navbar item remains active as long as you are in the /docs sectiono.

Actual Behavior

See above.

Reproducible Demo

See above

Activity

  1. endiliey commented on Nov 6, 2019

    @endiliey
    Contributor

    I don't think its a bug. The thing is, themeConfig.navbar.links is just a helper for you to link to internal pages, and "Docs" is just a Label.

    In docusaurus, it is possible to have multiple sidebars. See https://v2.docusaurus.io/docs/sidebar
    Example:

    // sidebars.js
    module.exports = {
      docs: {
        Docusaurus: ['introduction', 'design-principles', 'contributing'],
        'Getting Started': ['installation', 'configuration'],
      },
      "API": {
        'API Reference': [
          'cli',
          'docusaurus-core',
          'docusaurus.config.js',
          'lifecycle-apis',
        ],
      },
    };

    I could change my themeConfig.navbar.links to

    // docusaurus/config.js
    module.exports = {
      themeConfig: {
        navbar: {
          links: [
            {to: 'docs/introduction', label: 'Introduction', position: 'left'},
            {to: 'docs/cli', label: 'API', position: 'left'},
            // ... other links
          ],
        }
    }

    Which yields accessing /docs/introduction
    1

    /docs/cli
    2

    It's gonna be weird if i go to /docs/cli, both Navbar introduction and API is highlighted according to your expected behavior

  2. binarylogic commented on Nov 6, 2019

    @binarylogic
    ContributorAuthor

    Thanks. I understand your example but is anyone actually doing that? It seems like you're favoring an edge case at the expense of sacrificing the commonly desired behavior. A much better solution to your example would be a sub-menu under docs. Ex:

    - Docs (/docs)
       - Introduction (/docs/introduction)
       - API (/docs/api)
    

    It appears Infima supports this, and I noticed it is a feedback request.

    It's typically best practice for the navigation organization to follow the URL structure.

    Does that make sense? Do you agree?

  3. binarylogic commented on Nov 6, 2019

    @binarylogic
    ContributorAuthor

    Oh, and it's still not clear how I can enable the /docs route, even if that's just redirecting to another page. Having /docs 404 is a pretty poor user experience.

  4. endiliey commented on Nov 7, 2019

    @endiliey
    Contributor

    I guess the main problem is more on how to create /docs route.

    Because if /docs exist.

    {to: 'docs', label: 'Docs', position: 'left'},

    Will always be highlighted when you are in /docs/introduction for example. Our navbar highlighting is powered by react-router NavLink.

    You might want to wait #1946 to land first before you can actually create /docs on your own even if its a redirect

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions