React helmet Not working from Server when change route

hi all .
I want to use the helmet to render the meta tags in the head With SSR .

I used the following code for ssr :

import React from "react";
import { onPageLoad } from "meteor/server-render";
import { renderToString } from "react-dom/server";
import { ServerStyleSheet } from "styled-components"
import {Helmet} from "react-helmet";


import ServerRoutes from '../../Routes/Server-Routes';

onPageLoad(sink => {
  const sheet = new ServerStyleSheet();
  const html = renderToString(sheet.collectStyles(
    <ServerRoutes location={sink.request.url} />
  ));

  sink.renderIntoElementById("App", html);
  const helmet = Helmet.renderStatic();
  sink.appendToHead(helmet.title);
  sink.appendToHead(helmet.meta);
  
});

But this code works well for home page ( / ) .

But in other URLs, the tags do not change . And again the Home Page tags are rendered.

For example, the server on the Register page also renders the Home page tags.

What is really the problem?

Use react-helmet-async

1 Like

@rjdavid
Do i really have to use Context in this package? Isnt there another way?

@rjdavid
How to use this react-helmet-async on the Server Side .
The description of this package is not clear to me .
please HELP me

You need to be familiar with React Context