diff --git a/src/pages/ArticlePage.tsx b/src/pages/ArticlePage.tsx index 5639dd2..5e7f988 100644 --- a/src/pages/ArticlePage.tsx +++ b/src/pages/ArticlePage.tsx @@ -18,6 +18,7 @@ export function ArticlePage() { const location = useLocation(); const [articleData, setArticleData] = useState
(null); const [error, setError] = useState(null); + const [loading, setLoading] = useState(true); // Получть предыдущее состояние местоположения или создать путь по умолчанию const backTo = location.state?.from || '/'; @@ -30,6 +31,8 @@ export function ArticlePage() { } catch (error) { setError('Не удалось загрузить статью'); console.error(error); + } finally { + setLoading(false); } }; @@ -40,11 +43,21 @@ export function ArticlePage() { window.scrollTo(0, 0); }, [id]); - if (!articleData) { + if (loading) { + return ( +
+ Загрузка статьи... +
+ ); + } + + if (error || !articleData) { return (
-

Статья не найдена

+

+ {error || 'Статья не найдена'} +

Назад на главную diff --git a/src/utils/api.ts b/src/utils/api.ts index 5f5b60d..ff61df9 100644 --- a/src/utils/api.ts +++ b/src/utils/api.ts @@ -1,10 +1,10 @@ import axios from 'axios'; // Берем 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({ - baseURL: `${API_URL}/api` + baseURL: API_URL ? `${API_URL}/api` : '/api', }); api.interceptors.request.use((config) => {