wouter icon indicating copy to clipboard operation
wouter copied to clipboard

Redirect is not loading static file

Open KaiDevrim opened this issue 2 years ago • 1 comments

Hello, so I am trying to redirect to a static file like so


import { Redirect, Route } from "wouter-preact";
import "./app.css";
import Header from './components/header/header';
import Navbar from './components/navbar/Navbar';
import Blog from './pages/blog/blog';
import Penguin from './pages/blog/posts/penguin';
import Contact from './pages/contact/contact';
import Now from './pages/now/now';

export function App() {
  return (
    <>
      <>
        <Navbar />
        <>
          <Route path="/" component={Header} />
          <Route component={Penguin} path="/penguin" />
          <Route component={Blog} path="/blog" />
          <Route component={Now} path="/now" />
          <Route component={Contact} path="/contact" />
        </>
      </>
      <Route path="/resume">
        <Redirect to="KaiResume.pdf" />
      </Route>
    </>
  );
}

For some reason the NavBar element is still loaded in despite not being a part of page and the pdf does not load. I can go to Kai_Resume.pdf manually and it works but /resume does not.

KaiDevrim avatar Feb 25 '22 08:02 KaiDevrim

what <Redirect> component do, actually is:

 navigate(options.to || options.href, options)

then the path KaiResume.pdf, no component match this path.

cbbfcd avatar Mar 04 '22 14:03 cbbfcd

Hi @KaiDevrim, what you're trying to achieve is to perform a normal page navigation (e.g. navigation caused by clicking on a regular link) with the library that relies on pushState API. So when you're calling navigate("Kai_Resume.pdf") it is more or less equivalent to pushState("Kai_Resume.pdf") and your browser simply interprets it as "change the url in the address bar to "Kai_Resume.pdf") which it does.

molefrog avatar Nov 02 '22 18:11 molefrog