Skip to content

Commit

Permalink
replacement scrollToTop by ScrollRestoration of react-router-dom
Browse files Browse the repository at this point in the history
  • Loading branch information
Franqsanz committed Jun 12, 2024
1 parent bff2ce8 commit 2e53b3b
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 48 deletions.
50 changes: 25 additions & 25 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
"react-icons": "5.2.1",
"react-intersection-observer": "9.10.2",
"react-lazy-load": "4.0.1",
"react-router-dom": "6.23.0",
"react-router-dom": "6.23.1",
"react-share": "4.4.1",
"zustand": "4.5.2"
},
Expand Down
13 changes: 5 additions & 8 deletions src/pages/layout/Layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,15 @@ import { Outlet } from 'react-router-dom';
import { SkeletonMain } from '@components/skeletons/SkeletonMain';
import { Nav } from '@components/nav/Nav';
import { Footer } from '@components/Footer';
import { ScrollToTop } from '@utils/ScrollToTop';

export function Layout() {
return (
<>
<ScrollToTop>
<Nav />
<Suspense fallback={<SkeletonMain />}>
<Outlet />
</Suspense>
<Footer />
</ScrollToTop>
<Nav />
<Suspense fallback={<SkeletonMain />}>
<Outlet />
</Suspense>
<Footer />
</>
);
}
9 changes: 7 additions & 2 deletions src/routes.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { lazy } from 'react';
import { createBrowserRouter } from 'react-router-dom';
import { ScrollRestoration, createBrowserRouter } from 'react-router-dom';

import { Home } from '@pages/Home';
import { Login } from '@pages/Login';
Expand All @@ -25,7 +25,12 @@ const NewBook = lazy(() => import('@pages/NewBook'));
export const routes = createBrowserRouter([
{
path: '/',
element: <Layout />,
element: (
<>
<ScrollRestoration />
<Layout />
</>
),
errorElement: <div>Error 500 o Error Boundary</div>,
children: [
{
Expand Down
12 changes: 0 additions & 12 deletions src/utils/ScrollToTop.tsx

This file was deleted.

0 comments on commit 2e53b3b

Please sign in to comment.