-
-
Notifications
You must be signed in to change notification settings - Fork 122
/
Copy pathindex.js
33 lines (31 loc) · 980 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import { useRouter } from 'next/router'
import DesktopHeader from './desktop/header'
import MobileHeader from './mobile/header'
import StickyBar from './sticky-bar'
import { PriceCarouselProvider } from './price-carousel'
export default function Navigation ({ sub }) {
const router = useRouter()
const path = router.asPath.split('?')[0]
// TODO: this works but it can be better
const isCustomDomain = sub && !path.includes(`/~${sub}`)
const props = {
prefix: sub ? `/~${sub}` : '',
path,
pathname: router.pathname,
topNavKey: isCustomDomain
? path.split('/')[1] ?? ''
: path.split('/')[sub ? 2 : 1] ?? '',
dropNavKey: isCustomDomain
? path.split('/').slice(1).join('/')
: path.split('/').slice(sub ? 2 : 1).join('/'),
isCustomDomain,
sub
}
return (
<PriceCarouselProvider>
<DesktopHeader {...props} />
<MobileHeader {...props} />
<StickyBar {...props} />
</PriceCarouselProvider>
)
}