|
1 |
| -import React from 'react' |
2 |
| -import { Switch, Route, Redirect } from 'react-router-dom' |
| 1 | +import React, { useEffect, useState } from 'react' |
| 2 | +import { Switch, Route, Redirect, useLocation } from 'react-router-dom' |
3 | 3 | import { Loader, Responsive } from 'decentraland-ui'
|
4 | 4 | import { usePageTracking } from 'decentraland-dapps/dist/hooks/usePageTracking'
|
5 | 5 |
|
6 | 6 | import { locations } from 'routing/locations'
|
7 | 7 | import LoadingPage from 'components/LoadingPage'
|
8 | 8 | import MobilePage from 'components/MobilePage'
|
9 | 9 | import { ProtectedRoute } from 'modules/ProtectedRoute'
|
| 10 | +import { Props } from './AppRoutes.types' |
10 | 11 |
|
11 | 12 | const ScenesPage = React.lazy(() => import('components/ScenesPage'))
|
12 | 13 | const HomePage = React.lazy(() => import('components/HomePage'))
|
@@ -39,7 +40,17 @@ const CurationPage = React.lazy(() => import('components/CurationPage'))
|
39 | 40 | const TemplatesPage = React.lazy(() => import('components/TemplatesPage'))
|
40 | 41 | const TemplateDetailPage = React.lazy(() => import('components/TemplateDetailPage'))
|
41 | 42 |
|
42 |
| -export function AppRoutes() { |
| 43 | +export function AppRoutes({ saveLastLocation }: Props) { |
| 44 | + // Save the last location |
| 45 | + const location = useLocation() |
| 46 | + const [currentRoute, setCurrentRoute] = useState(location.pathname) |
| 47 | + useEffect(() => { |
| 48 | + if (currentRoute !== location.pathname) { |
| 49 | + saveLastLocation(currentRoute) |
| 50 | + setCurrentRoute(location.pathname) |
| 51 | + } |
| 52 | + }, [location.pathname, currentRoute]) |
| 53 | + |
43 | 54 | usePageTracking()
|
44 | 55 | return (
|
45 | 56 | <React.Suspense fallback={<Loader size="huge" active />}>
|
|
0 commit comments