Skip to content

Inconsistent Redirect component behavior #3351

@marikaner

Description

@marikaner

🐛 Bug Report

Running docusaurus with redirects locally and on Github Pages produces different results. I have a markdown file that is supposed to redirect to another page:

---
id: redirect-to-a
---

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

<Redirect to='a' />

When running locally requesting <path>/redirect-to-a in a browser redirects me to <path>/a which is exactly what I want. On Github Pages it (sometimes) redirects me to <path>/redirect-to-a/a which gives me a 404. I have had multiple occasions where this worked for one page, but not the other.

Have you read the Contributing Guidelines on issues?

yes

To Reproduce

  1. For a local version I ran docusaurus start.
  2. For the remote version I understand that docusaurus deploy is used.

Expected behavior

Local and remote redirect behavior is the same.

Actual Behavior

Local and remote redirect behavior differ.

Your Environment

  • Docusaurus version used: 2.0.0-alpha.61
  • Environment name and version (e.g. Chrome 78.0.3904.108, Node.js 10.17.0): Chrome 84.0.4147.135 (Official Build) (64-bit) (although we also tried other browsers),
  • Operating system and version (desktop or mobile): macOS 10.15.6

Reproducible Demo

I will give my best to provide this soon. I am a total newbie to docusaurus, so it will take me some more time to be able to reproduce this. In the mean time, maybe somebody has an idea as is.

One more thing that I tried was running docusaurus build and then docusaurus serve but it seems that this does not help me understand the issue because the resulting site did not have any css and redirects didn't redirect anywhere.

Workaround

Btw, I also found a workaround that might be helpful to other encountering this, although I am not 100% happy with it, because I need to know the <path> for it:

---
id: redirect-to-a
---

import {Redirect} from '@docusaurus/router';
import useBaseUrl from '@docusaurus/useBaseUrl';

<Redirect to={useBaseUrl('<path>/a')} />

Metadata

Metadata

Assignees

No one assigned

    Labels

    closed: duplicateThis issue or pull request already exists in another issue or pull request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions