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

Links missing a leading slash trigger a page reload #437

Open
JoelLefkowitz opened this issue Dec 30, 2022 · 0 comments
Open

Links missing a leading slash trigger a page reload #437

JoelLefkowitz opened this issue Dec 30, 2022 · 0 comments

Comments

@JoelLefkowitz
Copy link

Links of the form <Link href="path" /> rather than <Link href="/path" /> that are missing the leading slash are routed but trigger a page reload. It's an easy mistake to make since the routing occurs as expected and a difficult problem to diagnose.

Possible solutions:

  • Don't allow routes missing the leading slash
  • Don't trigger the reload
  • Mention it in the readme

Example:

import Router, { Link } from "preact-router";
import { VNode, render } from "preact";

const Home = (): VNode => (
  <>
    <Link href="/about">/about</Link>
    <br />
    <Link href="about">about (matches but reloads)</Link>
  </>
);

const About = (): VNode => <Link href="/home">/home</Link>

render(
  <Router>
    <Home default path="/" />
    <About path="/about" />
  </Router>,
  document.getElementById("root") as HTMLDivElement
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant