Skip to content

Commit 8c6fbcc

Browse files
committed
Added 404 page
1 parent 4370d42 commit 8c6fbcc

File tree

5 files changed

+25
-4
lines changed

5 files changed

+25
-4
lines changed

components/languages.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,15 @@ const Container = styled.div`
2828
`;
2929

3030
export function Languages() {
31-
const { locales, push } = useRouter();
31+
const { locales, push, pathname } = useRouter();
3232

3333
const handleLocaleClick = (locale: Locale) => () => {
3434
gtag.event({
3535
action: 'i18n_click',
3636
category: 'Locale',
3737
label: locale,
3838
});
39-
push('/', '/', { locale });
39+
push(pathname, pathname, { locale });
4040
};
4141

4242
return (

components/template.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { GlobalStyles } from 'styles/globals';
55
import styled, { ThemeProvider } from 'styled-components';
66
import { tokens } from 'styles/theme';
77
import { FlexColumnCentered } from 'styles/extends';
8+
import { Languages } from './languages';
89

910
const Page = styled.section`
1011
padding: 2rem;
@@ -37,6 +38,7 @@ export function PageTemplate({ t, title, children }: PageTemplateProps) {
3738
<title>{title}</title>
3839
<link rel="icon" href="/favicon.ico" />
3940
</Head>
41+
<Languages />
4042
<Main>{children}</Main>
4143
<Footer>
4244
<a href="/"> {t('author')} ©.</a> {t('footer')}

i18n/index.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ const portuguese = {
88
bio:
99
'Um entusiasta apaixonado por Typecript e engenheiro de software frontend do Brasil',
1010
footer: 'Todos os direitos reservados',
11+
backtohome: 'Ir a página inicial 🏡',
12+
404: 'Ops esta página não foi encontrada.',
1113
};
1214

1315
const english = {
@@ -16,6 +18,8 @@ const english = {
1618
bio:
1719
'A passionate Typescript enthusiast and frontend software engineer from Brazil',
1820
footer: 'All rights reserved',
21+
backtohome: 'Go to home page 🏡',
22+
404: 'Ops this page could not be found.',
1923
};
2024

2125
const locales = {

pages/404.tsx

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import { NextPage } from 'next';
2+
import Link from 'next/link';
3+
import { Translate } from 'i18n';
4+
import { PageTemplate } from 'components/template';
5+
6+
type NotFoundProps = {
7+
t: Translate;
8+
};
9+
const NotFound: NextPage<NotFoundProps> = ({ t }) => (
10+
<PageTemplate t={t} title={t(404)}>
11+
<h1>🤔 404</h1>
12+
<p>{t(404)}</p>
13+
<Link href="/">{t('backtohome')}</Link>
14+
</PageTemplate>
15+
);
16+
17+
export default NotFound;

pages/index.tsx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import { PageTemplate } from 'components/template';
55
import styled from 'styled-components';
66

77
import * as gtag from 'lib/gtag';
8-
import { Languages } from 'components/languages';
98

109
const Image = styled(NextImage)`
1110
border-radius: 50%;
@@ -68,7 +67,6 @@ const Home: NextPage<HomeProps> = ({ t }) => (
6867
<PageTemplate t={t} title={t('author')}>
6968
<h1>{t('welcome')}</h1>
7069
<p>{t('bio')}</p>
71-
<Languages />
7270
<Image
7371
src="/takah.jpg"
7472
alt="Picture of the author"

0 commit comments

Comments
 (0)