{"id":335514,"date":"2022-07-09T09:00:17","date_gmt":"2022-07-09T09:00:17","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=335514"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=335514","title":{"rendered":"<span>Telegram Web Apps (\u041f\u043e\u0432\u0442\u043e\u0440\u043d\u043e\u0435 \u043e\u0442\u043a\u0440\u044b\u0442\u0438\u0435 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0435\u0439 \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u044b)<\/span>"},"content":{"rendered":"<div><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p>15 \u0430\u043f\u0440\u0435\u043b\u044f \u043a\u043e\u043c\u0430\u043d\u0434\u0430 \u0442\u0435\u043b\u0435\u0433\u0440\u0430\u043c \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u0438\u043b\u0430 \u043d\u0430\u043c \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u0440\u0430\u0437\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0442\u044c \u0432\u0435\u0431 \u0431\u043e\u0442\u043e\u0432.<\/p>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u0432\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0435 \u0441 \u0431\u043e\u0442\u0430\u043c\u0438 \u0441\u0442\u0430\u043b\u043e \u043e\u0447\u0435\u043d\u044c \u0438\u043d\u0442\u0435\u0440\u0430\u043a\u0442\u0438\u0432\u043d\u044b\u043c, \u0442\u0430\u043a \u043a\u0430\u043a \u043c\u044b \u043e\u0431\u043b\u0430\u0434\u0430\u0435\u043c \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c\u044e \u0438\u043d\u0442\u0435\u0433\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0432 \u0431\u043e\u0442\u043e\u0432 \u043f\u043e\u043b\u043d\u043e\u0446\u0435\u043d\u043d\u044b\u0435 \u0432\u0435\u0431-\u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f.<\/p>\n<p>\u0412 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0435 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u0432\u0435\u0431 \u0430\u043f\u043f \u0431\u043e\u0442\u0430 \u044f \u0441\u0442\u043e\u043b\u043a\u043d\u0443\u043b\u0441\u044f \u0441 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u043e\u0439, \u0447\u0442\u043e \u043f\u043e\u0441\u043b\u0435 \u0437\u0430\u043a\u0440\u044b\u0442\u0438\u044f \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u0430 \u0432\u0435\u0431 \u0430\u043f\u043f \u0438 \u043f\u043e\u0432\u0442\u043e\u0440\u043d\u043e\u043c \u0435\u0433\u043e \u043e\u0442\u043a\u0440\u044b\u0442\u0438\u0438 \u043c\u044b \u0442\u0435\u0440\u044f\u0435\u043c \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u044e\u044e \u0441\u0441\u044b\u043b\u043a\u0443 \u043d\u0430 \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u043d\u0430\u0445\u043e\u0434\u0438\u043b\u0441\u044f \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c, \u0438 \u0432\u0435\u0431 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u043e\u0442\u043a\u0440\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0441 \u0433\u043b\u0430\u0432\u043d\u043e\u0439 \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u044b.<\/p>\n<p>\u0421\u043f\u0435\u0440\u0432\u0430, \u043c\u043e\u0436\u0435\u0442 \u043f\u043e\u043a\u0430\u0437\u0430\u0442\u044c\u0441\u044f, \u0447\u0442\u043e \u044d\u0442\u043e \u043d\u0435 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u043e\u0439, \u043d\u043e \u043d\u0430 \u0441\u0430\u043c\u043e\u043c \u0434\u0435\u043b\u0435 \u043e\u0447\u0435\u043d\u044c \u043b\u0435\u0433\u043a\u043e \u0441\u043b\u0443\u0447\u0430\u0439\u043d\u043e \u0437\u0430\u043a\u0440\u044b\u0442\u044c \u0432\u0435\u0431-\u043e\u043a\u043d\u043e, \u0442\u0430\u043a \u043a\u0430\u043a \u043e\u043d\u043e \u043d\u0435 \u043e\u0442\u043a\u0440\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u043d\u0430 \u0432\u0435\u0441\u044c \u044d\u043a\u0440\u0430\u043d, \u0430 \u0447\u0442\u043e\u0431\u044b \u0437\u0430\u043a\u0440\u044b\u0442\u044c \u0435\u0433\u043e, \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u043f\u043e\u0442\u044f\u043d\u0443\u0442\u044c \u0435\u0433\u043e \u0432\u043d\u0438\u0437 \u0438 \u043c\u044b \u0442\u0435\u0440\u044f\u0435\u043c \u0432\u0441\u0451 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0435\u0435 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f.<\/p>\n<p>\u0412 \u0441\u0432\u043e\u0451\u043c \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0438 \u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e React, mobX \u0438 React Router Dom v6. \u041f\u0435\u0440\u0432\u043e\u0435, \u0447\u0442\u043e \u043f\u0440\u0438\u0445\u043e\u0434\u0438\u0442 \u0432 \u0433\u043e\u043b\u043e\u0432\u0443, \u044d\u0442\u043e \u043f\u043e\u0434\u043f\u0438\u0441\u0430\u0442\u044c\u0441\u044f \u043d\u0430 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0435 \u043d\u0430\u0432\u0438\u0433\u0430\u0446\u0438\u0438 \u0438 \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u0442\u044c \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0435\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0432 localStorage \u0438\u043b\u0438 cookies, \u044f \u0432\u044b\u0431\u0440\u0430\u043b cookie, \u0441 \u0432\u0440\u0435\u043c\u0435\u043d\u0435\u043c \u0436\u0438\u0437\u043d\u0438 10 \u043c\u0438\u043d\u0443\u0442.<\/p>\n<p>\u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043d\u0430 \u043a\u043e\u0434. \u0421\u043e\u0437\u0434\u0430\u0451\u043c location-provider.tsx<\/p>\n<pre><code class=\"typescript\">import React from \"react\" import { useLocation, useNavigate } from \"react-router-dom\" import Cookies from \"js-cookie\"  interface LocationProviderProps { children: React.ReactNode }  const LocationProvider: React.FC&lt;LocationProviderProps> = ({ children }) => {   const location = useLocation()   const navigate = useNavigate()    React.useEffect(() => {     const currentLocation = Cookies.get(\"location_app\")     if (!currentLocation) return     navigate(currentLocation)   }, [])    React.useEffect(() => {     const tenMinutes = new Date(new Date().getTime() + 10 * 60 * 1000)     Cookies.set(\"location_app\", location.pathname, {       expires: tenMinutes,     })   }, [location])  return &lt;>{children}&lt;\/> }  export default LocationProvider<\/code><\/pre>\n<p>\u0418\u043c\u043f\u043e\u0440\u0442\u0438\u0440\u0443\u0435\u043c \u0435\u0433\u043e \u0432 App.tsx \u0438 \u043e\u0431\u043e\u0440\u0430\u0447\u0438\u0432\u0430\u0435\u043c \u043d\u0430\u0448\u0438 \u0440\u043e\u0443\u0442\u044b<\/p>\n<pre><code class=\"typescript\">import React from \"react\" import { BrowserRouter, Route, Routes } from \"react-router-dom\" import LocationProvider from \"providers\/location-provider\"  import { AppsPage } from \".\/pages\/apps\" import { DevelopersPage } from \".\/pages\/developers\" import { FavoritesPage } from \".\/pages\/favorites\" import { SearchPage } from \".\/pages\/search\"  function App() {   return (     &lt;BrowserRouter>       &lt;LocationProvider>         &lt;Routes>           &lt;Route index element={&lt;AppsPage \/>} \/>           &lt;Route path=\"\/apps\" element={&lt;AppsPage \/>} \/>           &lt;Route path=\"\/apps\/:appId\" element={&lt;AppDetailPage \/>} \/>           &lt;Route path=\"\/favorites\" element={&lt;FavoritesPage \/>} \/>           &lt;Route path=\"\/search\" element={&lt;SearchPage \/>} \/>           &lt;Route path=\"\/developers\" element={&lt;DevelopersPage \/>} \/>         &lt;\/Routes>       &lt;\/LocationProvider>     &lt;\/BrowserRouter>   ) }  export default App<\/code><\/pre>\n<p>\u041e\u0442\u043b\u0438\u0447\u043d\u043e, \u0442\u0435\u043f\u0435\u0440\u044c \u043f\u043e\u0441\u043b\u0435 \u0437\u0430\u043a\u0440\u044b\u0442\u0438\u044f \u0438 \u043e\u0442\u043a\u0440\u044b\u0442\u0438\u044f \u0432\u0435\u0431 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u0443 \u043d\u0430\u0441 \u0431\u0443\u0434\u0435\u0442 \u043e\u0442\u043a\u0440\u044b\u0432\u0430\u0442\u044c\u0441\u044f \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u044f\u044f \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u0430, \u043d\u043e!<\/p>\n<p>\u0422\u0443\u0442 \u0435\u0441\u0442\u044c \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0430, \u044d\u0442\u043e \u0442\u043e, \u0447\u0442\u043e \u0435\u0441\u043b\u0438 \u043f\u0440\u0438 \u043e\u0442\u043a\u0440\u044b\u0442\u043e\u043c \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0438 \u043f\u0435\u0440\u0435\u0439\u0442\u0438 \u043d\u0430 \u0434\u0440\u0443\u0433\u0443\u044e \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u0443 \u0447\u0435\u0440\u0435\u0437 \u0441\u0442\u0440\u043e\u043a\u0443 \u0432\u0432\u043e\u0434\u0430 URL, \u043d\u0430\u0441 \u0431\u0443\u0434\u0435\u0442 \u0440\u0435\u0434\u0438\u0440\u0435\u043a\u0442\u0438\u0442\u044c \u043d\u0430\u0437\u0430\u0434. \u041d\u043e \u0443 \u0432\u0435\u0431 \u0431\u043e\u0442\u043e\u0432 \u043d\u0435\u0442 \u0430\u0434\u0440\u0435\u0441\u043d\u043e\u0439 \u0441\u0442\u0440\u043e\u043a\u0438, \u0437\u043d\u0430\u0447\u0438\u0442 \u043d\u0430 \u044d\u0442\u043e\u043c \u043c\u043e\u0436\u043d\u043e \u043e\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u044c\u0441\u044f?<\/p>\n<p>\u0414\u0430, \u0435\u0441\u043b\u0438 \u0432\u0430\u043c \u044d\u0442\u043e\u0433\u043e \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e, \u0442\u043e \u044d\u0442\u043e \u0431\u0443\u0434\u0435\u0442 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0432 \u0432\u0435\u0431 \u0431\u043e\u0442\u0430\u0445. \u041d\u043e \u0443 \u0432\u0430\u0441 \u0431\u0443\u0434\u0443\u0442 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b \u043f\u0440\u0438 \u043e\u0442\u043a\u0440\u044b\u0442\u0438\u0438 \u0432\u0430\u0448\u0435\u0433\u043e \u0432\u0435\u0431 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u0432\u043d\u0435 \u0432\u0435\u0431 \u0431\u043e\u0442\u043e\u0432, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 \u0443 \u0432\u0430\u0441 \u0435\u0441\u0442\u044c \u043e\u043d\u043b\u0430\u0439\u043d \u043c\u0430\u0433\u0430\u0437\u0438\u043d, \u0432\u044b \u0431\u044b \u0445\u043e\u0442\u0435\u043b\u0438 \u0432\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u043e\u0432\u0430\u0442\u044c \u0441 \u043d\u0438\u043c \u0438 \u0432 \u0442\u0435\u043b\u0435\u0433\u0440\u0430\u043c \u0432\u0435\u0431 \u0430\u043f\u043f \u0438 \u043f\u0440\u043e\u0441\u0442\u043e \u043a\u0430\u043a \u0432\u0435\u0431 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u043e\u0435 \u043f\u043e \u0430\u0434\u0440\u0435\u0441\u0443, \u0447\u0442\u043e \u0442\u043e\u0433\u0434\u0430?<\/p>\n<p>\u0414\u0443\u043c\u0430\u0435\u043c \u0434\u0430\u043b\u044c\u0448\u0435, \u0432 DOM API \u0443 \u043e\u0431\u044a\u0435\u043a\u0442\u0430 window \u0435\u0441\u0442\u044c event <code>onbeforeunload<\/code>, \u043a\u0430\u0436\u0435\u0442\u0441\u044f \u044d\u0442\u043e \u0442\u043e, \u0447\u0442\u043e \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e, \u0431\u0443\u0434\u0435\u043c \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u0442\u044c \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u0439 URL \u043f\u0435\u0440\u0435\u0434 \u0437\u0430\u043a\u0440\u044b\u0442\u0438\u0435\u043c \u0432\u0435\u0431 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f, \u043f\u0440\u043e\u0431\u0443\u0435\u043c.<\/p>\n<p>\u041e\u0431\u043d\u043e\u0432\u0438\u043c \u043d\u0430\u0448 location-provider.tsx<\/p>\n<pre><code class=\"typescript\">import React from \"react\" import { useLocation, useNavigate } from \"react-router-dom\" import Cookies from \"js-cookie\"  interface LocationProviderProps { children: React.ReactNode }  const LocationProvider: React.FC&lt;LocationProviderProps> = ({ children }) => {   const location = useLocation()   const navigate = useNavigate()      React.useEffect(() => {     const currentLocation = Cookies.get(\"location_app\")     if (!currentLocation) return     navigate(currentLocation)   }, [])    React.useEffect(() => {     window.onbeforeunload = (e: BeforeUnloadEvent) => {     e.preventDefault()     const tenMinutes = new Date(new Date().getTime() + 10 * 60 * 1000)       Cookies.set(\"location_app\", location.pathname, {       expires: tenMinutes,       })     }   }, [location])   return &lt;>{children}&lt;\/> }  export default LocationProvider<\/code><\/pre>\n<p>\u041f\u0440\u043e\u0431\u0443\u0435\u043c \u0433\u0443\u043b\u044f\u0442\u044c \u043f\u043e \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044e \u0447\u0435\u0440\u0435\u0437 \u0430\u0434\u0440\u0435\u0441\u043d\u0443\u044e \u0441\u0442\u0440\u043e\u043a\u0443, \u0440\u0435\u0434\u0438\u0440\u0435\u043a\u0442\u0430 \u043d\u0430\u0437\u0430\u0434 \u043d\u0435\u0442, \u043e\u0442\u043b\u0438\u0447\u043d\u043e, \u0442\u0430\u043a \u0436\u0435 \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u0435\u0442\u0441\u044f \u0441\u0441\u044b\u043b\u043a\u0430 \u043f\u0440\u0438 \u0437\u0430\u043a\u0440\u044b\u0442\u0438\u0438 \u0432\u043a\u043b\u0430\u0434\u043a\u0438 \u0441 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435\u043c, \u0442\u043e \u0447\u0442\u043e \u043c\u044b \u0438 \u0445\u043e\u0442\u0435\u043b\u0438! \u041f\u0440\u043e\u0431\u0443\u0435\u043c \u0432 \u0442\u0435\u043b\u0435\u0433\u0440\u0430\u043c, \u0431\u0430\u0446 \u0438 \u0442\u0443\u0442 \u044d\u0442\u043e \u0441\u043e\u0432\u0441\u0435\u043c \u043d\u0435 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442, \u043f\u043e\u0447\u0435\u043c\u0443?<\/p>\n<p>\u0414\u0435\u043b\u043e \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e \u0442\u0435\u043b\u0435\u0433\u0440\u0430\u043c \u043e\u0442\u043a\u0440\u044b\u0432\u0430\u0435\u0442 \u0431\u0440\u0430\u0443\u0437\u0435\u0440\u043d\u043e\u0435 \u043e\u043a\u043d\u043e \u0432 \u0442\u0430\u043a \u043d\u0430\u0437\u044b\u0432\u0430\u0435\u043c\u043e\u043c WebView, \u044f \u043d\u0435 \u0441\u0438\u043b\u0435\u043d \u0432 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0435 \u043c\u043e\u0431\u0438\u043b\u044c\u043d\u044b\u0445 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0439, \u043d\u043e \u0437\u043d\u0430\u044e, \u0447\u0442\u043e \u044d\u0442\u0430 \u0448\u0442\u0443\u043a\u0430 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043e\u0442\u043a\u0440\u044b\u0432\u0430\u0442\u044c \u0431\u0440\u0430\u0443\u0437\u0435\u0440 \u0432\u043d\u0443\u0442\u0440\u0438 \u043c\u043e\u0431\u0438\u043b\u044c\u043d\u044b\u0445 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0439, \u043d\u043e \u0443 \u043d\u0438\u0445 \u0435\u0441\u0442\u044c \u0441\u0432\u043e\u0438 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u044f \u0438 \u044d\u0442\u043e \u043a\u0430\u043a \u0440\u0430\u0437 \u043e\u0434\u043d\u043e \u0438\u0437 \u043d\u0438\u0445.<\/p>\n<p>\u0427\u0442\u043e \u0442\u043e\u0433\u0434\u0430? \u041e\u0442\u043b\u0438\u0447\u043d\u044b\u043c \u0440\u0435\u0448\u0435\u043d\u0438\u0435\u043c \u0431\u0443\u0434\u0435\u0442 \u0432\u0435\u0440\u043d\u0443\u0442\u044c\u0441\u044f \u043a \u043f\u0435\u0440\u0432\u043e\u043c\u0443 \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u0443, \u043d\u043e \u0432\u043a\u043b\u044e\u0447\u0438\u0442\u044c \u043a\u0435\u0448\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0442\u043e\u043b\u044c\u043a\u043e \u0434\u043b\u044f \u0442\u0435\u043b\u0435\u0433\u0440\u0430\u043c \u0432\u0435\u0431 \u0430\u043f\u043f. \u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043d\u0430 \u0442\u043e, \u0447\u0442\u043e \u0443 \u043d\u0430\u0441 \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u043e\u0441\u044c.<\/p>\n<pre><code class=\"typescript\">import React from \"react\" import { useLocation, useNavigate } from \"react-router-dom\" import Cookies from \"js-cookie\"  interface LocationProviderProps { children: React.ReactNode }  const LocationProvider: React.FC&lt;LocationProviderProps> = ({ children }) => { if (!window.Telegram.WebApp.initData.length) { return &lt;>{children}&lt;\/> } else { return &lt;LocationProviderInner>{children}&lt;\/LocationProviderInner> } }  const LocationProviderInner: React.FC&lt;LocationProviderProps> = ({ children, }) => {   const location = useLocation()   const navigate = useNavigate()    const redirectToLastPage = () => {     const currentLocation = Cookies.get(\"location_app\")     if (!currentLocation) return     navigate(currentLocation)   }      React.useEffect(() => {     if (location.key === \"default\") redirectToLastPage()      Cookies.set(\"location_app\", location.pathname, {       expires: new Date(new Date().getTime() + 10 * 60 * 1000), \/\/ 10 min     })   }, [location.key])  return &lt;>{children}&lt;\/> }  export default LocationProvider<\/code><\/pre>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u0443 \u043d\u0430\u0441 \u043a\u0435\u0448\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0431\u0443\u0434\u0435\u0442 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0442\u043e\u043b\u044c\u043a\u043e \u0432 \u0442\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435, \u0435\u0441\u043b\u0438 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u0437\u0430\u043f\u0443\u0449\u0435\u043d\u043e \u0438\u0437 \u0442\u0435\u043b\u0435\u0433\u0440\u0430\u043c \u0432\u0435\u0431 \u0431\u043e\u0442\u0430.<\/p>\n<p>\u0421\u043f\u0430\u0441\u0438\u0431\u043e \u0437\u0430 \u0447\u0442\u0435\u043d\u0438\u0435!<\/p>\n<\/div>\n<\/div>\n<\/div>\n<div class=\"v-portal\" style=\"display:none;\"><\/div>\n<\/div>\n<p> <!----> <!----><br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/post\/676016\/\"> https:\/\/habr.com\/ru\/post\/676016\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p>15 \u0430\u043f\u0440\u0435\u043b\u044f \u043a\u043e\u043c\u0430\u043d\u0434\u0430 \u0442\u0435\u043b\u0435\u0433\u0440\u0430\u043c \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u0438\u043b\u0430 \u043d\u0430\u043c \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u0440\u0430\u0437\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0442\u044c \u0432\u0435\u0431 \u0431\u043e\u0442\u043e\u0432.<\/p>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u0432\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0435 \u0441 \u0431\u043e\u0442\u0430\u043c\u0438 \u0441\u0442\u0430\u043b\u043e \u043e\u0447\u0435\u043d\u044c \u0438\u043d\u0442\u0435\u0440\u0430\u043a\u0442\u0438\u0432\u043d\u044b\u043c, \u0442\u0430\u043a \u043a\u0430\u043a \u043c\u044b \u043e\u0431\u043b\u0430\u0434\u0430\u0435\u043c \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c\u044e \u0438\u043d\u0442\u0435\u0433\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0432 \u0431\u043e\u0442\u043e\u0432 \u043f\u043e\u043b\u043d\u043e\u0446\u0435\u043d\u043d\u044b\u0435 \u0432\u0435\u0431-\u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f.<\/p>\n<p>\u0412 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0435 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u0432\u0435\u0431 \u0430\u043f\u043f \u0431\u043e\u0442\u0430 \u044f \u0441\u0442\u043e\u043b\u043a\u043d\u0443\u043b\u0441\u044f \u0441 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u043e\u0439, \u0447\u0442\u043e \u043f\u043e\u0441\u043b\u0435 \u0437\u0430\u043a\u0440\u044b\u0442\u0438\u044f \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u0430 \u0432\u0435\u0431 \u0430\u043f\u043f \u0438 \u043f\u043e\u0432\u0442\u043e\u0440\u043d\u043e\u043c \u0435\u0433\u043e \u043e\u0442\u043a\u0440\u044b\u0442\u0438\u0438 \u043c\u044b \u0442\u0435\u0440\u044f\u0435\u043c \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u044e\u044e \u0441\u0441\u044b\u043b\u043a\u0443 \u043d\u0430 \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u043d\u0430\u0445\u043e\u0434\u0438\u043b\u0441\u044f \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c, \u0438 \u0432\u0435\u0431 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u043e\u0442\u043a\u0440\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0441 \u0433\u043b\u0430\u0432\u043d\u043e\u0439 \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u044b.<\/p>\n<p>\u0421\u043f\u0435\u0440\u0432\u0430, \u043c\u043e\u0436\u0435\u0442 \u043f\u043e\u043a\u0430\u0437\u0430\u0442\u044c\u0441\u044f, \u0447\u0442\u043e \u044d\u0442\u043e \u043d\u0435 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u043e\u0439, \u043d\u043e \u043d\u0430 \u0441\u0430\u043c\u043e\u043c \u0434\u0435\u043b\u0435 \u043e\u0447\u0435\u043d\u044c \u043b\u0435\u0433\u043a\u043e \u0441\u043b\u0443\u0447\u0430\u0439\u043d\u043e \u0437\u0430\u043a\u0440\u044b\u0442\u044c \u0432\u0435\u0431-\u043e\u043a\u043d\u043e, \u0442\u0430\u043a \u043a\u0430\u043a \u043e\u043d\u043e \u043d\u0435 \u043e\u0442\u043a\u0440\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u043d\u0430 \u0432\u0435\u0441\u044c \u044d\u043a\u0440\u0430\u043d, \u0430 \u0447\u0442\u043e\u0431\u044b \u0437\u0430\u043a\u0440\u044b\u0442\u044c \u0435\u0433\u043e, \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u043f\u043e\u0442\u044f\u043d\u0443\u0442\u044c \u0435\u0433\u043e \u0432\u043d\u0438\u0437 \u0438 \u043c\u044b \u0442\u0435\u0440\u044f\u0435\u043c \u0432\u0441\u0451 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0435\u0435 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f.<\/p>\n<p>\u0412 \u0441\u0432\u043e\u0451\u043c \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0438 \u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e React, mobX \u0438 React Router Dom v6. \u041f\u0435\u0440\u0432\u043e\u0435, \u0447\u0442\u043e \u043f\u0440\u0438\u0445\u043e\u0434\u0438\u0442 \u0432 \u0433\u043e\u043b\u043e\u0432\u0443, \u044d\u0442\u043e \u043f\u043e\u0434\u043f\u0438\u0441\u0430\u0442\u044c\u0441\u044f \u043d\u0430 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0435 \u043d\u0430\u0432\u0438\u0433\u0430\u0446\u0438\u0438 \u0438 \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u0442\u044c \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0435\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0432 localStorage \u0438\u043b\u0438 cookies, \u044f \u0432\u044b\u0431\u0440\u0430\u043b cookie, \u0441 \u0432\u0440\u0435\u043c\u0435\u043d\u0435\u043c \u0436\u0438\u0437\u043d\u0438 10 \u043c\u0438\u043d\u0443\u0442.<\/p>\n<p>\u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043d\u0430 \u043a\u043e\u0434. \u0421\u043e\u0437\u0434\u0430\u0451\u043c location-provider.tsx<\/p>\n<pre><code class=\"typescript\">import React from \"react\" import { useLocation, useNavigate } from \"react-router-dom\" import Cookies from \"js-cookie\"  interface LocationProviderProps { children: React.ReactNode }  const LocationProvider: React.FC&lt;LocationProviderProps> = ({ children }) => {   const location = useLocation()   const navigate = useNavigate()    React.useEffect(() => {     const currentLocation = Cookies.get(\"location_app\")     if (!currentLocation) return     navigate(currentLocation)   }, [])    React.useEffect(() => {     const tenMinutes = new Date(new Date().getTime() + 10 * 60 * 1000)     Cookies.set(\"location_app\", location.pathname, {       expires: tenMinutes,     })   }, [location])  return &lt;>{children}&lt;\/> }  export default LocationProvider<\/code><\/pre>\n<p>\u0418\u043c\u043f\u043e\u0440\u0442\u0438\u0440\u0443\u0435\u043c \u0435\u0433\u043e \u0432 App.tsx \u0438 \u043e\u0431\u043e\u0440\u0430\u0447\u0438\u0432\u0430\u0435\u043c \u043d\u0430\u0448\u0438 \u0440\u043e\u0443\u0442\u044b<\/p>\n<pre><code class=\"typescript\">import React from \"react\" import { BrowserRouter, Route, Routes } from \"react-router-dom\" import LocationProvider from \"providers\/location-provider\"  import { AppsPage } from \".\/pages\/apps\" import { DevelopersPage } from \".\/pages\/developers\" import { FavoritesPage } from \".\/pages\/favorites\" import { SearchPage } from \".\/pages\/search\"  function App() {   return (     &lt;BrowserRouter>       &lt;LocationProvider>         &lt;Routes>           &lt;Route index element={&lt;AppsPage \/>} \/>           &lt;Route path=\"\/apps\" element={&lt;AppsPage \/>} \/>           &lt;Route path=\"\/apps\/:appId\" element={&lt;AppDetailPage \/>} \/>           &lt;Route path=\"\/favorites\" element={&lt;FavoritesPage \/>} \/>           &lt;Route path=\"\/search\" element={&lt;SearchPage \/>} \/>           &lt;Route path=\"\/developers\" element={&lt;DevelopersPage \/>} \/>         &lt;\/Routes>       &lt;\/LocationProvider>     &lt;\/BrowserRouter>   ) }  export default App<\/code><\/pre>\n<p>\u041e\u0442\u043b\u0438\u0447\u043d\u043e, \u0442\u0435\u043f\u0435\u0440\u044c \u043f\u043e\u0441\u043b\u0435 \u0437\u0430\u043a\u0440\u044b\u0442\u0438\u044f \u0438 \u043e\u0442\u043a\u0440\u044b\u0442\u0438\u044f \u0432\u0435\u0431 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u0443 \u043d\u0430\u0441 \u0431\u0443\u0434\u0435\u0442 \u043e\u0442\u043a\u0440\u044b\u0432\u0430\u0442\u044c\u0441\u044f \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u044f\u044f \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u0430, \u043d\u043e!<\/p>\n<p>\u0422\u0443\u0442 \u0435\u0441\u0442\u044c \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0430, \u044d\u0442\u043e \u0442\u043e, \u0447\u0442\u043e \u0435\u0441\u043b\u0438 \u043f\u0440\u0438 \u043e\u0442\u043a\u0440\u044b\u0442\u043e\u043c \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0438 \u043f\u0435\u0440\u0435\u0439\u0442\u0438 \u043d\u0430 \u0434\u0440\u0443\u0433\u0443\u044e \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u0443 \u0447\u0435\u0440\u0435\u0437 \u0441\u0442\u0440\u043e\u043a\u0443 \u0432\u0432\u043e\u0434\u0430 URL, \u043d\u0430\u0441 \u0431\u0443\u0434\u0435\u0442 \u0440\u0435\u0434\u0438\u0440\u0435\u043a\u0442\u0438\u0442\u044c \u043d\u0430\u0437\u0430\u0434. \u041d\u043e \u0443 \u0432\u0435\u0431 \u0431\u043e\u0442\u043e\u0432 \u043d\u0435\u0442 \u0430\u0434\u0440\u0435\u0441\u043d\u043e\u0439 \u0441\u0442\u0440\u043e\u043a\u0438, \u0437\u043d\u0430\u0447\u0438\u0442 \u043d\u0430 \u044d\u0442\u043e\u043c \u043c\u043e\u0436\u043d\u043e \u043e\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u044c\u0441\u044f?<\/p>\n<p>\u0414\u0430, \u0435\u0441\u043b\u0438 \u0432\u0430\u043c \u044d\u0442\u043e\u0433\u043e \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e, \u0442\u043e \u044d\u0442\u043e \u0431\u0443\u0434\u0435\u0442 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0432 \u0432\u0435\u0431 \u0431\u043e\u0442\u0430\u0445. \u041d\u043e \u0443 \u0432\u0430\u0441 \u0431\u0443\u0434\u0443\u0442 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b \u043f\u0440\u0438 \u043e\u0442\u043a\u0440\u044b\u0442\u0438\u0438 \u0432\u0430\u0448\u0435\u0433\u043e \u0432\u0435\u0431 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u0432\u043d\u0435 \u0432\u0435\u0431 \u0431\u043e\u0442\u043e\u0432, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 \u0443 \u0432\u0430\u0441 \u0435\u0441\u0442\u044c \u043e\u043d\u043b\u0430\u0439\u043d \u043c\u0430\u0433\u0430\u0437\u0438\u043d, \u0432\u044b \u0431\u044b \u0445\u043e\u0442\u0435\u043b\u0438 \u0432\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u043e\u0432\u0430\u0442\u044c \u0441 \u043d\u0438\u043c \u0438 \u0432 \u0442\u0435\u043b\u0435\u0433\u0440\u0430\u043c \u0432\u0435\u0431 \u0430\u043f\u043f \u0438 \u043f\u0440\u043e\u0441\u0442\u043e \u043a\u0430\u043a \u0432\u0435\u0431 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u043e\u0435 \u043f\u043e \u0430\u0434\u0440\u0435\u0441\u0443, \u0447\u0442\u043e \u0442\u043e\u0433\u0434\u0430?<\/p>\n<p>\u0414\u0443\u043c\u0430\u0435\u043c \u0434\u0430\u043b\u044c\u0448\u0435, \u0432 DOM API \u0443 \u043e\u0431\u044a\u0435\u043a\u0442\u0430 window \u0435\u0441\u0442\u044c event <code>onbeforeunload<\/code>, \u043a\u0430\u0436\u0435\u0442\u0441\u044f \u044d\u0442\u043e \u0442\u043e, \u0447\u0442\u043e \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e, \u0431\u0443\u0434\u0435\u043c \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u0442\u044c \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u0439 URL \u043f\u0435\u0440\u0435\u0434 \u0437\u0430\u043a\u0440\u044b\u0442\u0438\u0435\u043c \u0432\u0435\u0431 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f, \u043f\u0440\u043e\u0431\u0443\u0435\u043c.<\/p>\n<p>\u041e\u0431\u043d\u043e\u0432\u0438\u043c \u043d\u0430\u0448 location-provider.tsx<\/p>\n<pre><code class=\"typescript\">import React from \"react\" import { useLocation, useNavigate } from \"react-router-dom\" import Cookies from \"js-cookie\"  interface LocationProviderProps { children: React.ReactNode }  const LocationProvider: React.FC&lt;LocationProviderProps> = ({ children }) => {   const location = useLocation()   const navigate = useNavigate()      React.useEffect(() => {     const currentLocation = Cookies.get(\"location_app\")     if (!currentLocation) return     navigate(currentLocation)   }, [])    React.useEffect(() => {     window.onbeforeunload = (e: BeforeUnloadEvent) => {     e.preventDefault()     const tenMinutes = new Date(new Date().getTime() + 10 * 60 * 1000)       Cookies.set(\"location_app\", location.pathname, {       expires: tenMinutes,       })     }   }, [location])   return &lt;>{children}&lt;\/> }  export default LocationProvider<\/code><\/pre>\n<p>\u041f\u0440\u043e\u0431\u0443\u0435\u043c \u0433\u0443\u043b\u044f\u0442\u044c \u043f\u043e \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044e \u0447\u0435\u0440\u0435\u0437 \u0430\u0434\u0440\u0435\u0441\u043d\u0443\u044e \u0441\u0442\u0440\u043e\u043a\u0443, \u0440\u0435\u0434\u0438\u0440\u0435\u043a\u0442\u0430 \u043d\u0430\u0437\u0430\u0434 \u043d\u0435\u0442, \u043e\u0442\u043b\u0438\u0447\u043d\u043e, \u0442\u0430\u043a \u0436\u0435 \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u0435\u0442\u0441\u044f \u0441\u0441\u044b\u043b\u043a\u0430 \u043f\u0440\u0438 \u0437\u0430\u043a\u0440\u044b\u0442\u0438\u0438 \u0432\u043a\u043b\u0430\u0434\u043a\u0438 \u0441 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435\u043c, \u0442\u043e \u0447\u0442\u043e \u043c\u044b \u0438 \u0445\u043e\u0442\u0435\u043b\u0438! \u041f\u0440\u043e\u0431\u0443\u0435\u043c \u0432 \u0442\u0435\u043b\u0435\u0433\u0440\u0430\u043c, \u0431\u0430\u0446 \u0438 \u0442\u0443\u0442 \u044d\u0442\u043e \u0441\u043e\u0432\u0441\u0435\u043c \u043d\u0435 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442, \u043f\u043e\u0447\u0435\u043c\u0443?<\/p>\n<p>\u0414\u0435\u043b\u043e \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e \u0442\u0435\u043b\u0435\u0433\u0440\u0430\u043c \u043e\u0442\u043a\u0440\u044b\u0432\u0430\u0435\u0442 \u0431\u0440\u0430\u0443\u0437\u0435\u0440\u043d\u043e\u0435 \u043e\u043a\u043d\u043e \u0432 \u0442\u0430\u043a \u043d\u0430\u0437\u044b\u0432\u0430\u0435\u043c\u043e\u043c WebView, \u044f \u043d\u0435 \u0441\u0438\u043b\u0435\u043d \u0432 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0435 \u043c\u043e\u0431\u0438\u043b\u044c\u043d\u044b\u0445 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0439, \u043d\u043e \u0437\u043d\u0430\u044e, \u0447\u0442\u043e \u044d\u0442\u0430 \u0448\u0442\u0443\u043a\u0430 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043e\u0442\u043a\u0440\u044b\u0432\u0430\u0442\u044c \u0431\u0440\u0430\u0443\u0437\u0435\u0440 \u0432\u043d\u0443\u0442\u0440\u0438 \u043c\u043e\u0431\u0438\u043b\u044c\u043d\u044b\u0445 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0439, \u043d\u043e \u0443 \u043d\u0438\u0445 \u0435\u0441\u0442\u044c \u0441\u0432\u043e\u0438 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u044f \u0438 \u044d\u0442\u043e \u043a\u0430\u043a \u0440\u0430\u0437 \u043e\u0434\u043d\u043e \u0438\u0437 \u043d\u0438\u0445.<\/p>\n<p>\u0427\u0442\u043e \u0442\u043e\u0433\u0434\u0430? \u041e\u0442\u043b\u0438\u0447\u043d\u044b\u043c \u0440\u0435\u0448\u0435\u043d\u0438\u0435\u043c \u0431\u0443\u0434\u0435\u0442 \u0432\u0435\u0440\u043d\u0443\u0442\u044c\u0441\u044f \u043a \u043f\u0435\u0440\u0432\u043e\u043c\u0443 \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u0443, \u043d\u043e \u0432\u043a\u043b\u044e\u0447\u0438\u0442\u044c \u043a\u0435\u0448\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0442\u043e\u043b\u044c\u043a\u043e \u0434\u043b\u044f \u0442\u0435\u043b\u0435\u0433\u0440\u0430\u043c \u0432\u0435\u0431 \u0430\u043f\u043f. \u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043d\u0430 \u0442\u043e, \u0447\u0442\u043e \u0443 \u043d\u0430\u0441 \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u043e\u0441\u044c.<\/p>\n<pre><code class=\"typescript\">import React from \"react\" import { useLocation, useNavigate } from \"react-router-dom\" import Cookies from \"js-cookie\"  interface LocationProviderProps { children: React.ReactNode }  const LocationProvider: React.FC&lt;LocationProviderProps> = ({ children }) => { if (!window.Telegram.WebApp.initData.length) { return &lt;>{children}&lt;\/> } else { return &lt;LocationProviderInner>{children}&lt;\/LocationProviderInner> } }  const LocationProviderInner: React.FC&lt;LocationProviderProps> = ({ children, }) => {   const location = useLocation()   const navigate = useNavigate()    const redirectToLastPage = () => {     const currentLocation = Cookies.get(\"location_app\")     if (!currentLocation) return     navigate(currentLocation)   }      React.useEffect(() => {     if (location.key === \"default\") redirectToLastPage()      Cookies.set(\"location_app\", location.pathname, {       expires: new Date(new Date().getTime() + 10 * 60 * 1000), \/\/ 10 min     })   }, [location.key])  return &lt;>{children}&lt;\/> }  export default LocationProvider<\/code><\/pre>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u0443 \u043d\u0430\u0441 \u043a\u0435\u0448\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0431\u0443\u0434\u0435\u0442 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0442\u043e\u043b\u044c\u043a\u043e \u0432 \u0442\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435, \u0435\u0441\u043b\u0438 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u0437\u0430\u043f\u0443\u0449\u0435\u043d\u043e \u0438\u0437 \u0442\u0435\u043b\u0435\u0433\u0440\u0430\u043c \u0432\u0435\u0431 \u0431\u043e\u0442\u0430.<\/p>\n<p>\u0421\u043f\u0430\u0441\u0438\u0431\u043e \u0437\u0430 \u0447\u0442\u0435\u043d\u0438\u0435!<\/p>\n<\/div>\n<\/div>\n<\/div>\n<div class=\"v-portal\" style=\"display:none;\"><\/div>\n<\/div>\n<p> <!----> <!----><br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/post\/676016\/\"> https:\/\/habr.com\/ru\/post\/676016\/<\/a><br \/><\/br><\/br><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-335514","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/335514","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=335514"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/335514\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=335514"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=335514"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=335514"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}