Skip to content

Commit

Permalink
⭐ feat : React-Helmet 적용
Browse files Browse the repository at this point in the history
- title만 동적으로 바뀐다. 메타태그는 동적으로 바뀌지 않음을 볼 수 있다.
  • Loading branch information
crystal993 committed Nov 3, 2022
1 parent 38382d2 commit 0878117
Show file tree
Hide file tree
Showing 7 changed files with 4,494 additions and 160 deletions.
6 changes: 6 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/build/*.js
/config/*.js
/bower_components/foo/*.js
!.build
.build/*
!.build/test.js
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

# production
/build
.build

# misc
.DS_Store
Expand Down
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@
"@types/react-dom": "^18.0.8",
"axios": "0.27.2",
"dotenv": "^16.0.3",
"gatsby": "^4.24.6",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-helmet-async": "^1.3.0",
"react-router-dom": "^6.4.3",
"react-scripts": "5.0.1",
"styled-components": "^5.3.6",
Expand Down
16 changes: 11 additions & 5 deletions src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,20 @@ import GlobalStyle from './styles/GlobalStyle';
import { Reset } from 'styled-reset';
import Router from './router/Routers';
import CarListProvider from './context/CarListProvider';
import { Helmet } from 'react-helmet-async';

function App() {
return (
<CarListProvider>
<Reset />
<GlobalStyle />
<Router />
</CarListProvider>
<>
<Helmet>
<title>B2C Car Sharing</title>
</Helmet>
<CarListProvider>
<Reset />
<GlobalStyle />
<Router />
</CarListProvider>
</>
);
}

Expand Down
22 changes: 22 additions & 0 deletions src/components/metaTag/SEOMetaTag.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import React from 'react';
import { Helmet } from 'react-helmet-async';
import { useLocation } from 'react-router-dom';
import { convertAmount } from '../../utils/function/convertAmount';

const SEOMetaTag = () => {
const { state } = useLocation();
if (state)
return (
<Helmet>
<title>{`${state.attribute.brand} ${state.attribute.name}`}</title>
<meta property="og:type" content="website" />
<meta property="og:title" content={`${state.attribute.brand} ${state.attribute.name}`} />
<meta property="og:description" content={`월 ${convertAmount(state.amount)} 원`} />
<meta property="og:image" content={state.attribute.imageUrl} />

<link rel="canonical" href={state.url} />
</Helmet>
);
};

export default SEOMetaTag;
6 changes: 5 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,13 @@ import ReactDOM from 'react-dom/client';
import App from './App';
import { ThemeProvider } from 'styled-components';
import theme from './styles/theme';
import { HelmetProvider } from 'react-helmet-async';

const root = ReactDOM.createRoot(document.getElementById('root'));
root.render(
<ThemeProvider theme={theme}>
<App />
<HelmetProvider>
<App />
</HelmetProvider>
</ThemeProvider>
);
4,601 changes: 4,447 additions & 154 deletions yarn.lock

Large diffs are not rendered by default.

0 comments on commit 0878117

Please sign in to comment.