Исправление baseURL для работы на production. Подправлана фоновая надпись (загрузка...) при показе статьи.
This commit is contained in:
parent
6bb71bff44
commit
0a1a5d65d5
@ -18,6 +18,7 @@ export function ArticlePage() {
|
|||||||
const location = useLocation();
|
const location = useLocation();
|
||||||
const [articleData, setArticleData] = useState<Article | null>(null);
|
const [articleData, setArticleData] = useState<Article | null>(null);
|
||||||
const [error, setError] = useState<string | null>(null);
|
const [error, setError] = useState<string | null>(null);
|
||||||
|
const [loading, setLoading] = useState(true);
|
||||||
|
|
||||||
// Получть предыдущее состояние местоположения или создать путь по умолчанию
|
// Получть предыдущее состояние местоположения или создать путь по умолчанию
|
||||||
const backTo = location.state?.from || '/';
|
const backTo = location.state?.from || '/';
|
||||||
@ -30,6 +31,8 @@ export function ArticlePage() {
|
|||||||
} catch (error) {
|
} catch (error) {
|
||||||
setError('Не удалось загрузить статью');
|
setError('Не удалось загрузить статью');
|
||||||
console.error(error);
|
console.error(error);
|
||||||
|
} finally {
|
||||||
|
setLoading(false);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -40,11 +43,21 @@ export function ArticlePage() {
|
|||||||
window.scrollTo(0, 0);
|
window.scrollTo(0, 0);
|
||||||
}, [id]);
|
}, [id]);
|
||||||
|
|
||||||
if (!articleData) {
|
if (loading) {
|
||||||
|
return (
|
||||||
|
<div className="min-h-screen flex items-center justify-center text-gray-500">
|
||||||
|
Загрузка статьи...
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (error || !articleData) {
|
||||||
return (
|
return (
|
||||||
<div className="min-h-screen flex items-center justify-center">
|
<div className="min-h-screen flex items-center justify-center">
|
||||||
<div className="text-center">
|
<div className="text-center">
|
||||||
<h2 className="text-2xl font-bold text-gray-900 mb-4">Статья не найдена</h2>
|
<h2 className="text-2xl font-bold text-gray-900 mb-4">
|
||||||
|
{error || 'Статья не найдена'}
|
||||||
|
</h2>
|
||||||
<Link to={backTo} className="text-blue-600 hover:text-blue-800">
|
<Link to={backTo} className="text-blue-600 hover:text-blue-800">
|
||||||
Назад на главную
|
Назад на главную
|
||||||
</Link>
|
</Link>
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
import axios from 'axios';
|
import axios from 'axios';
|
||||||
|
|
||||||
// Берем baseURL из .env
|
// Берем baseURL из .env
|
||||||
const API_URL = import.meta.env.VITE_API_URL || 'http://localhost:5000';
|
const API_URL = import.meta.env.VITE_API_URL;
|
||||||
|
|
||||||
const api = axios.create({
|
const api = axios.create({
|
||||||
baseURL: `${API_URL}/api`
|
baseURL: API_URL ? `${API_URL}/api` : '/api',
|
||||||
});
|
});
|
||||||
|
|
||||||
api.interceptors.request.use((config) => {
|
api.interceptors.request.use((config) => {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user