Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

useHistory with external URL #8495

Closed
6 of 7 tasks
Cittjr opened this issue Jan 2, 2023 · 1 comment
Closed
6 of 7 tasks

useHistory with external URL #8495

Cittjr opened this issue Jan 2, 2023 · 1 comment
Labels
closed: working as intended This issue is intended behavior, there's no need to take any action. external This issue is caused by an external dependency and not Docusaurus.

Comments

@Cittjr
Copy link

Cittjr commented Jan 2, 2023

Have you read the Contributing Guidelines on issues?

Prerequisites

  • I'm using the latest version of Docusaurus.
  • I have tried the npm run clear or yarn clear command.
  • I have tried rm -rf node_modules yarn.lock package-lock.json and re-installing packages.
  • I have tried creating a repro with https://new.docusaurus.io.
  • I have read the console error message carefully (if applicable).

Description

Hello,

i am using the plugin "easyops-cn/docusaurus-search-local", this plugin create an autocomplete and when click on an element the code call the useHistory.push(url);.

But when i specify an external url (example: https://www.google.com/) the router open "http://localhost:3000/https://www.google.com/" not only "https://www.google.com/".

I have test with a single page and this page doesnt open the external url.

Reproducible demo

No response

Steps to reproduce

  1. Create a new page (pages/redirectTest.js)
  2. Set this code in the page:
import Layout from '@theme/Layout';
import {useLocation} from '@docusaurus/router';
import { useHistory } from "@docusaurus/router";

  
export default function PageRoute() {
  // React router provides the current component's route, even in SSR
  const location = useLocation();
  const history = useHistory();
  
  history.push("https://www.google.com/");
  
  return (
    <span>
      We are currently on <code>{location.pathname}</code>
    </span>
  );
}
  1. Launch the page

Expected behavior

i want to open an external url with the method push of the history

Actual behavior

The external url is not open, docusaurus detect the url for his system of route

Your environment

  • Public source code: None
  • Public site URL: None
  • Docusaurus version used: 2.2.0
  • Environment name and version (e.g. Chrome 89, Node.js 16.4): Chrome last & Node v16.15.1
  • Operating system and version (e.g. Ubuntu 20.04.2 LTS): Windows

Self-service

  • I'd be willing to fix this bug myself.
@Cittjr Cittjr added bug An error in the Docusaurus core causing instability or issues with its execution status: needs triage This issue has not been triaged by maintainers labels Jan 2, 2023
@Josh-Cena
Copy link
Collaborator

This is working as intended—external URLs should not use history.push, but window.location. This is why our Algolia plugin has a config to treat certain paths as external. See #5795

@Josh-Cena Josh-Cena closed this as not planned Won't fix, can't repro, duplicate, stale Jan 2, 2023
@Josh-Cena Josh-Cena added external This issue is caused by an external dependency and not Docusaurus. closed: working as intended This issue is intended behavior, there's no need to take any action. and removed bug An error in the Docusaurus core causing instability or issues with its execution status: needs triage This issue has not been triaged by maintainers labels Jan 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
closed: working as intended This issue is intended behavior, there's no need to take any action. external This issue is caused by an external dependency and not Docusaurus.
Projects
None yet
Development

No branches or pull requests

2 participants