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

dot in path breaks reload #2245

Closed
dusty opened this issue Feb 25, 2021 · 3 comments
Closed

dot in path breaks reload #2245

dusty opened this issue Feb 25, 2021 · 3 comments

Comments

@dusty
Copy link

dusty commented Feb 25, 2021

Describe the bug

In an app using an SPA router such as react-router-dom, when a dot exists in the path, one cannot link directly to that page or reload that page because it results in a 404 error.

I couldn't find any documentation on how to override that so it will follow a pattern such as checking if the file exists first and if not, then always falling back to the index.html file.

Reproduction

https://github.com/dusty/vitejs-path

import React from "react";
import { BrowserRouter, Link, Route, Switch } from "react-router-dom";
import { Item } from "./Item";

function App() {
  return (
    <BrowserRouter>
      <div>
        <p>
          <Link to="/items/1">Item 1</Link>
          <Link to="/items/1.1" style={{ marginLeft: "10px" }}>
            Item 1.1
          </Link>
        </p>
      </div>
      <Switch>
        <Route path="/items/:id">
          <Item />
        </Route>
      </Switch>
    </BrowserRouter>
  );
}

export default App;

System Info

vite/2.0.3 darwin-x64 node-v15.7.0

Logs (Optional if provided reproduction)

  vite:spa-fallback Not rewriting GET /items/1.1 because the path includes a dot (.) character. +3m
  vite:time 1ms   /items/1.1 +3m

2021-02-25 07 54 37

@jonaskuske
Copy link
Contributor

Take a look at this issue: #2190, the plugin linked in the last comment might solve your issue: https://www.npmjs.com/package/vite-plugin-rewrite-all

@dusty
Copy link
Author

dusty commented Feb 26, 2021

cool, thanks @jonaskuske

@dusty
Copy link
Author

dusty commented Feb 26, 2021

I can confirm that this worked for me.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants