vercel / serve

Static file serving and directory listing
https://npmjs.com/package/serve
MIT License
9.35k stars 687 forks source link

serve didn't work in routing with react-router and vite in production #790

Closed laminesadiki closed 11 months ago

laminesadiki commented 11 months ago

Description

I'm working in React project using Vite and React-Router.

I setup multiple pages using react router like this example

<BrowserRouter>
   <Routes>
      <Route path="/" element={<Home />} />
      <Route path="/login" element={<Login />} />
   </Routes>
</BrowserRouter>

When I build the application using tsc && vite build and serving the application via serve dist.

The main page works correctly but the/login path don't working; Give me a 404 error.

Can anyone suggest a solution for this situation ?

Library version

14.2.1

Node version

18.18.1

laminesadiki commented 11 months ago

I find a solution is running the with -s flag like dist serve -s dist