Cody Ng
Cody Ng

Reputation: 349

next-seo not render to <head> in SSR?

The SEO tags don't get rendered in SSR when using the next-seo package. I have tried

<NextSeo />

and

<Head><NextSeo /></Head>

to render code in a next.js page, but no luck.

Can anyone have any workaround solutions by using next-seo with SSR?

Thanks.

Upvotes: 1

Views: 1351

Answers (2)

Ruslan Novikov
Ruslan Novikov

Reputation: 1527

In my case works only like this:

<>
   <NextSeo
            title={titleSEO}
            description={descriptionSEO}
            openGraph={openGraph}
   />
   <Head>
            <link rel="icon" href="/favicon.ico"/>
   </Head>
   ...
</>
  • next: 12.1.4 in SSR mode
  • next-seo: 5.5.0

Upvotes: 0

Cody Ng
Cody Ng

Reputation: 349

I've just found that the reason is <PersistGate loading={null} persistor={persistor}></PersistGate>. Because I am using redux and persist-redux in react.

If I take out the <PersistGate> line, the meta tags are fine.

_app.js:

    return (
        <Provider store={store}>
            <PersistGate loading={null} persistor={persistor}>
                <StylesProvider>
                    <ThemeProvider theme={theme}>
                        <CssBaseline />
                        <Component {...pageProps} />
                    </ThemeProvider>
                </StylesProvider>
            </PersistGate>
        </Provider>
    );

What is the problem there? I must use redux+persist-redux....

Upvotes: 1

Related Questions