1- import React , { useState } from 'react'
1+ import React , { useState , useEffect } from 'react'
22import { routes , RouteType } from '../../routes/routes'
33import styled from 'styled-components'
44import { useTranslation } from 'react-i18next'
@@ -7,6 +7,7 @@ import Image from 'next/image'
77import { media } from '../../assets/styles/mixin'
88import SnsLink from './SnsLink'
99import PyconLogoWhite from '../../public/images/pyconkr_2022_logo_white.png'
10+ import Link from 'next/link'
1011
1112const Container = styled . nav `
1213 display: flex;
@@ -40,7 +41,7 @@ const ListItem = styled.li<{ active?: boolean }>`
4041 color: ${ ( props ) => props . theme . colors . white } ;
4142 position: relative;
4243`
43- export const Link = styled . a `
44+ export const BlockLink = styled ( Link ) `
4445 display: block;
4546 cursor: pointer;
4647`
@@ -131,6 +132,10 @@ const NavBar = (props: NavProps) => {
131132 router . push ( router . asPath , undefined , { locale : lang } )
132133 }
133134
135+ useEffect ( ( ) => {
136+ setOpenedSubMenu ( '' )
137+ } , [ router . pathname ] )
138+
134139 return (
135140 < Container isTransparent = { isHome } >
136141 < HomeLink href = "/" >
@@ -160,18 +165,18 @@ const NavBar = (props: NavProps) => {
160165 < SubMenuList >
161166 { route . subMenu . map ( ( subMenu , index ) => (
162167 < SubMenuListItem key = { index } >
163- < Link href = { getPath ( subMenu . path ) } >
168+ < BlockLink href = { getPath ( subMenu . path ) } >
164169 { t ( `pageTitle:${ subMenu . name } ` ) }
165- </ Link >
170+ </ BlockLink >
166171 </ SubMenuListItem >
167172 ) ) }
168173 </ SubMenuList >
169174 </ ListItem >
170175 ) : (
171176 < ListItem key = { index } active = { isActive ( route ) } >
172- < Link href = { getPath ( route . path ) } >
177+ < BlockLink href = { getPath ( route . path ) } >
173178 { t ( `pageTitle:${ route . name } ` ) }
174- </ Link >
179+ </ BlockLink >
175180 </ ListItem >
176181 )
177182 } ) }
0 commit comments