facebook / docusaurus

Easy to maintain open source documentation websites.
https://docusaurus.io
MIT License
55.96k stars 8.4k forks source link

Documentation-only sites do not work if baseUrl is not `/` #2404

Closed rlamana closed 4 years ago

rlamana commented 4 years ago

🐛 Bug Report

A docusaurus site (v2) without a landing page and documentation as the index page does not work if baseUrl is other than /.

It seems like @docusarus-utils.normalizeUrl is generating double forward slashes when routeBasePath is set to a single '/' in the docs plugin configuration.

For a baseUrl: 'metro/' and docs.routeBasePath: '/' the generated routes are:

...
/metro//2.0.0-alpha.43/using-plugins
/metro//2.0.0-alpha.43/using-themes
/metro//2.0.0-alpha.43/versioning
/metro//next/blog
/metro//next/cli
/metro//next/configuration
/metro//next/contributing
/metro//next/creating-pages
...

When navigating to /metro/next/blog, react-router finds no match and the "Page not found" message is loaded instead.

Have you read the Contributing Guidelines on issues?

Yes.

To Reproduce

Using docusaurus' website/ in the repository as an example:

  1. Set baseUrl to /metro/ in your docusaurus.config.js.
  2. Set routeBasePath to / in the @docusaurus/preset-classic.docs section of your docusaurus.config.js.
  3. Run yarn start
  4. Navigate to https://localhost:3000/metro/introduction
  5. "Page not found: is displayed.

Expected behavior

https://localhost:3000/metro/introduction should have loaded the Introduction page (in docs/introduction.md), just like https://localhost:3000/docs/introduction loads it when baseUrl and routeBasePath have their default values.

Your Environment

yangshun commented 4 years ago

Sorry our previous docs-only instructions were incorrect. We've updated it but have yet to publish it - https://v2.docusaurus.io/docs/next/configuration/#docs-only-mode

tnir commented 3 years ago

As I've got lost multiple times during several month to find this modification, I would like to add a note: as of 2.0.0-beta.0 (and 2.0.0-beta.1), the URL is at https://docusaurus.io/docs/docs-introduction#docs-only-mode

joe-bell commented 3 years ago

I'm also experiencing this issue locally with the setup above/in the docs:

module.exports = {
  baseUrl: "/docs/",
  presets: [
    [
      "@docusaurus/preset-classic",
      {
        docs: {
          sidebarPath: require.resolve("./sidebars.js"),
          path: "docs",
          routeBasePath: "/",
        },
        blog: false,
        theme: {
          customCss: require.resolve("./src/css/custom.css"),
        },
      },
    ],
  ],

Which works completely fine in development, but with build && serve will output

Screenshot 2021-06-07 at 20 49 04
slorber commented 3 years ago

@joe-bell this is a bug: https://github.com/facebook/docusaurus/issues/3291

To fix it locally you could probably move build to build/docs and run docusaurus serve again

joe-bell commented 3 years ago

Thanks for the quick response @slorber – moving the directory certainly seems to do the trick for now

In the meantime, I'll stick with:

docusaurus build --out-dir build/docs
sanamhub commented 2 years ago

I'm getting the same error at: https://blc-bit.github.io/notes/

Can anyone help?

GitHub repo: https://github.com/blc-bit/notes

Josh-Cena commented 2 years ago

@sanamhub Your site is working perfectly. What's the error? What's your desired effect?

Please don't necropost under a super-old issue. It's obviously resolved and irrelevant to your issue.

sanamhub commented 2 years ago

@sanamhub Your site is working perfectly. What's the error? What's your desired effect?

Please don't necropost under a super-old issue. It's obviously resolved and irrelevant to your issue.

I fixed it, thanks anyway!

nyakiomaina commented 1 year ago

@sanamhub Your site is working perfectly. What's the error? What's your desired effect? Please don't necropost under a super-old issue. It's obviously resolved and irrelevant to your issue.

I fixed it, thanks anyway!

how did you fix it?

sanamhub commented 1 year ago

how did you fix it?

I can't recall as of now 😞

haixuanTao commented 6 months ago

Just for people facing the same issue. Deleting baseUrl, building and putting back, removed the issue for me, lol.

Maybe a cache error somewhere.