-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3b7468e
commit 8a763bf
Showing
9 changed files
with
62 additions
and
67 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,39 @@ | ||
import { useEffect } from 'react'; | ||
import { css as csl } from '@linaria/core'; | ||
import 'ress'; | ||
import 'unfonts.css'; | ||
import { Outlet, useLocation } from 'react-router-dom'; | ||
|
||
import { Meta } from '@components/meta'; | ||
import { css, cx } from '@lib/css'; | ||
import { theme } from '@theme'; | ||
|
||
import { Routes } from './routing'; | ||
export const App = () => { | ||
// Extracts pathname property(key) from an object | ||
const { pathname } = useLocation(); | ||
|
||
export const App = () => ( | ||
<> | ||
<Meta /> | ||
<div | ||
className={cx( | ||
csl` | ||
// Automatically scrolls to top whenever pathname changes | ||
useEffect(() => { | ||
window.scrollTo(0, 0); | ||
}, [pathname]); | ||
|
||
return ( | ||
<> | ||
<Meta /> | ||
<div | ||
className={cx( | ||
csl` | ||
${theme.decl.font.size.step0} | ||
${theme.decl.font.sansSerif.regular} | ||
`, | ||
css` | ||
${theme.page.body} | ||
${theme.definitions} | ||
`, | ||
)} | ||
> | ||
<Routes /> | ||
</div> | ||
</> | ||
); | ||
css` | ||
${theme.page.body} | ||
${theme.definitions} | ||
`, | ||
)} | ||
> | ||
<Outlet /> | ||
</div> | ||
</> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,31 @@ | ||
import React from 'react'; | ||
import ReactDOM from 'react-dom/client'; | ||
import { HelmetProvider } from 'react-helmet-async'; | ||
import { BrowserRouter } from 'react-router-dom'; | ||
import { createBrowserRouter, RouterProvider } from 'react-router-dom'; | ||
|
||
// if (!Object.hasOwn) { | ||
// Object.hasOwn = (obj, prop) => Object.prototype.hasOwnProperty.call(obj, prop); | ||
// } | ||
import { App } from './app'; | ||
import { routes } from './routing'; | ||
|
||
const root = document.getElementById('root'); | ||
const router = createBrowserRouter(routes); | ||
|
||
if (root?.hasChildNodes()) { | ||
ReactDOM.hydrateRoot( | ||
root, | ||
<React.StrictMode> | ||
<BrowserRouter> | ||
<HelmetProvider> | ||
<App /> | ||
</HelmetProvider> | ||
</BrowserRouter> | ||
<HelmetProvider> | ||
<RouterProvider router={router} /> | ||
</HelmetProvider> | ||
</React.StrictMode>, | ||
); | ||
} else { | ||
ReactDOM.createRoot(root!).render( | ||
<React.StrictMode> | ||
<BrowserRouter> | ||
<HelmetProvider> | ||
<App /> | ||
</HelmetProvider> | ||
</BrowserRouter> | ||
<HelmetProvider> | ||
<RouterProvider router={router} /> | ||
</HelmetProvider> | ||
</React.StrictMode>, | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,21 @@ | ||
import { useEffect } from 'react'; | ||
import { Home } from '@pages/home'; | ||
import { Portfolio } from '@pages/portfolio'; | ||
import { Outlet, Route as ReactRoute, Routes as ReactRoutes, useLocation } from 'react-router-dom'; | ||
import { createRoutesFromElements, Route, Routes } from 'react-router-dom'; | ||
|
||
import { Article } from './article'; | ||
import { App } from '../app'; | ||
|
||
const ScrollToTop = () => { | ||
// Extracts pathname property(key) from an object | ||
const { pathname } = useLocation(); | ||
const others = ( | ||
<Route element={<App />}> | ||
<Route path="/" lazy={async () => ({ Component: (await import('../pages/home')).Home })} /> | ||
<Route | ||
path="/portfolio" | ||
lazy={async () => ({ Component: (await import('../pages/portfolio')).Portfolio })} | ||
/> | ||
<Route | ||
path="/portfolio/:id" | ||
lazy={async () => ({ Component: (await import('./article')).Article })} | ||
/> | ||
</Route> | ||
); | ||
|
||
// Automatically scrolls to top whenever pathname changes | ||
useEffect(() => { | ||
window.scrollTo(0, 0); | ||
}, [pathname]); | ||
export const AppRoutes = <Routes>{others}</Routes>; | ||
|
||
return <Outlet />; | ||
}; | ||
|
||
export const Routes = () => { | ||
return ( | ||
<ReactRoutes> | ||
<ReactRoute element={<ScrollToTop />}> | ||
<ReactRoute path="/" element={<Home />} /> | ||
<ReactRoute path="/portfolio" element={<Portfolio />} /> | ||
<ReactRoute path="/portfolio/:id" element={<Article />} /> | ||
</ReactRoute> | ||
</ReactRoutes> | ||
); | ||
}; | ||
export const routes = createRoutesFromElements(others); |