Skip to content

Hard refresh leading to 404 error when using vite --host with Vite + Hono + Cloudflare Worker template #21314

@KyleRicardo

Description

@KyleRicardo

Describe the bug

Hi community,
I'm using https://github.com/cloudflare/templates/tree/main/vite-react-template to create a project.
And try to introduce tanstack router in it, for file-based routing.
Since I'm building an mobile-first app, so I need to test in my real phone.
I used pnpm dev --host i.e. vite --host to expose network access from my computer, so that my phone can use my computer's IP and port to visit the website.
However, when I visit the network address, and route to the about page, and then do a hard refresh (press F5), the app throws a 404 error.
But when using localhost:5173, there's no such problem. Only using the IP will cause this problem.

BTW, pnpm preview --host will cause this issue as well. Seems something wrong with --host function.

Since this template involves Vite + React + Cloudflare Workers + Tanstack Router, I really have no idea which part is causing this problem.
Can you help me troubleshoot this issue? Thank you so much.

Reproduction

https://github.com/KyleRicardo/vite-tanstack-router-template

Steps to reproduce

  1. Clone my minimal reproduction repo.
  2. You may need to delete pnpm-lock.json first to get Cloudflare's workerd working for your machine's arch.
  3. Run pnpm install
  4. Use pnpm dev --host to start dev server
  5. Use <your_local_ip>:5173 to visit the dev website
  6. Use the about button to navigate to about page
  7. Refresh the page, and you will get 404 Not Found error message

System Info

System:
    OS: macOS 15.1
    CPU: (8) arm64 Apple M1
    Memory: 184.05 MB / 8.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 22.14.0 - /Users/kylericardo/.local/share/mise/installs/node/22.14.0/bin/node
    npm: 11.2.0 - /Users/kylericardo/.local/share/mise/installs/node/22.14.0/bin/npm
    pnpm: 10.10.0 - /Users/kylericardo/.local/share/mise/installs/node/22.14.0/bin/pnpm
  Browsers:
    Chrome: 143.0.7499.170
    Firefox: 127.0.2
    Safari: 18.1
  npmPackages:
    @vitejs/plugin-react: 5.1.1 => 5.1.1 
    vite: ^6.0.0 => 6.4.1

Used Package Manager

pnpm

Logs

No response

Validations

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions