При заходе на localhost/ всё работает, однако если перезагрузить страницу на, например, /sign/in, то получаю 404.
Роуты на React Router Dom
import axios from 'axios';
import { createRoot } from 'react-dom/client';
import './styles.css';
import 'react-toastify/ReactToastify.min.css';
import { QueryClient, QueryClientProvider } from 'react-query';
import { BrowserRouter, Route, Routes } from 'react-router-dom';
import { ToastContainer } from 'react-toastify';
import { Error } from './pages/error';
import { List } from './pages/list';
import { Sign } from './pages/sign';
import { SignIn } from './pages/sign/in';
import { SignUp } from './pages/sign/up';
import { RedirectPage } from './redirectPage';
const client = new QueryClient();
axios.defaults.baseURL = 'http://localhost:8080/api/';
createRoot(document.getElementById('root')!).render(
<QueryClientProvider client={client}>
<ToastContainer
theme="dark"
pauseOnHover={false}
position="top-center"
autoClose={5000}
closeButton={false}
closeOnClick
/>
<BrowserRouter>
<Routes>
<Route path="*" element={<Error />} />
<Route index element={<RedirectPage />} />
<Route path="sign" element={<Sign />}>
<Route path="in" element={<SignIn />} />
<Route path="up" element={<SignUp />} />
</Route>
<Route path="list" element={<List />} />
</Routes>
</BrowserRouter>
</QueryClientProvider>,
);
nginx.conf
server {
listen 80 default_server;
listen [::]:80 default_server;
index index.html index.htm index.nginx-debian.html;
error_page 404 403 500 503 /index.html;
location / {
[pre-existing configurations, if applicable]
autoindex on;
autoindex_exact_size off;
root /usr/share/nginx/html;
if (!-e $request_filename){
rewrite ^/(.*) /index.html;
}
try_files $uri /index.html;
}
}
Dockerfile
FROM node:alpine as build
WORKDIR /app
COPY . .
RUN npm install
RUN npm run build
# production environment
FROM nginx:stable-alpine
COPY --from=build /app/dist /usr/share/nginx/html
COPY --from=build /app/nginx.conf /etc/nginx/sites-enabled/default
EXPOSE 80
CMD ["nginx", "-g", "daemon off;"]