6

Since I don't have a landing page, I would like to redirect to the main doc page docs/main

I tried to follow the instructions: https://docusaurus.io/docs/en/site-creation#docs-landing-page from v1, but they don't seem to work for v2. Can someone please give me detail instructions on how to accomplish this?

I have very limited experience with React.

Dharman
  • 30,962
  • 25
  • 85
  • 135
Maru
  • 71
  • 1
  • 3

3 Answers3

5

Be sure to add the baseUrl via useBaseUrl just to be more robust.

Few ways of doing it:

1. useEffect

import useBaseUrl from '@docusaurus/useBaseUrl';

function Home() {
  React.useEffect(() => {
    window.location.href = useBaseUrl('/docs/main');
  }, []);
  return null;
}

2. <Redirect/>

Alternatively, use the <Redirect> component: https://v2.docusaurus.io/docs/docusaurus-core#redirect-

3. Create index.html page in static folder

And include the following code for redirects: https://v1.docusaurus.io/docs/en/site-creation#docs-landing-page

Yangshun Tay
  • 49,270
  • 33
  • 114
  • 141
3

Configure the docId of the Docs nav item to point to your main page

File: docusaurus.config.js

{
  type: 'doc',
  docId: 'main',
  position: 'left',
  label: 'Docs',
}

Add the following slug to the top of your main page to have /docs redirect to it

File: docs/main.mdx

--- 
slug: /
---

Then create the following file to redirect /docs/main to /docs

File: src/pages/docs/main.js

import React from 'react';
import {Redirect} from '@docusaurus/router';

export default function Home() {
  return <Redirect to="/docs" />;
};
0

You can switch to docs only mode. You can refer to the official docs here:

https://docusaurus.io/docs/docs-introduction#docs-only-mode

Change your docusaurus.config.js and add routeBasePath:'/' to docs object.

  module.exports = {
  // ...
  presets: [
    '@docusaurus/preset-classic',
    {
      docs: {
        routeBasePath: '/', // Serve the docs at the site's root
        /* other docs plugin options */
      },
      blog: false, // Optional: disable the blog plugin
      // ...
    },
  ],
};
  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Jul 30 '22 at 23:01
  • While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. - [From Review](/review/late-answers/32356072) – monim Aug 02 '22 at 09:58