Reputation: 111
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.
Upvotes: 10
Views: 8629
Reputation: 11
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
// ...
},
],
};
Upvotes: 1
Reputation: 51
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" />;
};
Upvotes: 5
Reputation: 53179
Be sure to add the baseUrl
via useBaseUrl
just to be more robust.
Few ways of doing it:
useEffect
import useBaseUrl from '@docusaurus/useBaseUrl';
function Home() {
React.useEffect(() => {
window.location.href = useBaseUrl('/docs/main');
}, []);
return null;
}
<Redirect/>
Alternatively, use the <Redirect>
component: https://v2.docusaurus.io/docs/docusaurus-core#redirect-
index.html
page in static
folderAnd include the following code for redirects: https://v1.docusaurus.io/docs/en/site-creation#docs-landing-page
Upvotes: 6