I'm trying to show different navigations based on if it is the "Homepage" or if it is a page that contains "docs" (e.g. docs/1, docs/2, docs/3) in its URL. I'm just getting blanks on the "docs"-case - it feels like I am missing something here?
Here's my code so far:
const router = useRouter()
const path = router?.asPath
if (path === '/docs/') {
return (
<>
<Head>
<title>{pageTitle}</title>
{description && <meta name="description" content={description} />}
</Head>
<Layout
navigation={navigation1}
title={title}
tableOfContents={tableOfContents}
>
<Component {...pageProps} />
</Layout>
</>
)
}
if (path === '/') {
return (
<>
<Head>
<title>{pageTitle}</title>
{description && <meta name="description" content={description} />}
</Head>
<Layout
navigation={navigation}
title={title}
tableOfContents={tableOfContents}
>
<Component {...pageProps} />
</Layout>
</>
)
}
NextJS has a built-in route system. You can just create a docs.js file in the pages folder. You can either create different navigations directly in /pages/docs.js or a dynamic component for it.
Here is more about routing https://nextjs.org/docs/routing/introduction
Hope this answers your question :)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With