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

Router basepath and Link absolute paths #148

Closed
Seavenly opened this issue Aug 30, 2018 · 3 comments
Closed

Router basepath and Link absolute paths #148

Seavenly opened this issue Aug 30, 2018 · 3 comments
Labels
duplicate This issue or pull request already exists

Comments

@Seavenly
Copy link

Is the intended behavior for Link absolute paths to not respect the Router basepath prop? The following example does not have working links:
https://codesandbox.io/s/vv3q3v9yo0

import React from "react";
import ReactDOM from "react-dom";
import { Router, Link } from "@reach/router";

import "./styles.css";

const App = () => (
  <Router basepath="/apple">
    <Page path="/">
      <HomePage path="/" />
      <OtherPage path="/other" />
    </Page>
  </Router>
);

const Page = ({ children }) => (
  <div>
    <ul>
      <li>
        <Link to="/">Home</Link>
      </li>
      <li>
        <Link to="/other">Other</Link>
      </li>
    </ul>
    <hr />
    {children}
  </div>
);

const HomePage = () => <h1>Home Page</h1>;
const OtherPage = () => <h1>Other Page</h1>;

const rootElement = document.getElementById("root");
ReactDOM.render(<App />, rootElement);

If I change the Links to relative links then they respect the basepath prop.

<Link to="">Home</Link>
<Link to="other">Other</Link>
@gablabelle
Copy link

gablabelle commented Oct 29, 2018

I'm facing the same issue.

If basepath is /fr, I was hoping that <Link to={/${slug}} /> would go to http://www.site.com/fr/slug but it goes http://www.site.com/slug.

I guess we'll have to prefix with the basepath ... Weird because when using a basepath you want it to be the root of your app no?

@kevinrambaud
Copy link

Same thing for me, I'm surprised by this behavior.

@astik
Copy link

astik commented Jan 21, 2019

Hi all,
I think this issue can be set as a duplicate from #78.
You should take a look on it, there is a workaround there ... not perfect, but it works ... in a way =)

@mtliendo mtliendo added the duplicate This issue or pull request already exists label Sep 12, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
duplicate This issue or pull request already exists
Projects
None yet
Development

No branches or pull requests

5 participants