Skip to content

Commit 4ccc832

Browse files
handle undefined currentPath to prevent runtime error
1 parent 1434b0f commit 4ccc832

1 file changed

Lines changed: 9 additions & 3 deletions

File tree

components/layout/Meta.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,15 @@ import Script from 'next/script';
55

66
export default function Meta() {
77
const currentPath = usePathname();
8-
const firstSegment = '/' + currentPath.split('/')[1] || [];
9-
const meta =
10-
firstSegment in pageMeta ? pageMeta[firstSegment] : pageMeta['/'];
8+
let firstSegment = '/';
9+
if (currentPath) {
10+
const segments = currentPath.split('/');
11+
if (segments[1]) {
12+
firstSegment = '/' + segments[1];
13+
}
14+
}
15+
16+
const meta = pageMeta[firstSegment] ? pageMeta[firstSegment] : pageMeta['/'];
1117
return (
1218
<>
1319
<Head>

0 commit comments

Comments
 (0)