-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Meta tags ssr #1
Comments
Look at the example https://github.com/s-yadav/react-meta-tags/blob/master/examples/app.js Mainly look at the code match({
routes, location: req.url
}, (error, redirectLocation, renderProps) => {
if(error) {
res.status(500).send(error.message);
} else if (redirectLocation) {
res.redirect(302, redirectLocation.pathname + redirectLocation.search)
} else if (renderProps) {
let reactString;
const metaTagsInstance = MetaTagsServer();
try{
reactString = ReactDomServer.renderToString(
<MetaTagsContext extract = {metaTagsInstance.extract}>
<RouterContext {...renderProps}/>
</MetaTagsContext>
);
}
catch(e){
console.log(e);
res.status(500).send(e.stack);
return;
}
const meta = metaTagsInstance.renderToString();
const template = `
<!doctype html>
<html lang="en">
<head>
<meta charSet="utf-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<meta http-equiv="x-ua-compatible" content="ie=edge">
${meta}
<!-- Bootstrap CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.4/css/bootstrap.min.css" integrity="2hfp1SzUoho7/TsGGGDaFdsuuDL0LX2hnUp6VkX3CUQ2K4K+xjboZdsXyp4oUHZj" crossorigin="anonymous">
</head>
<body>
<div id="app">${reactString}</div>
<script src="http://localhost:9000/bundle.js"></script>
</body>
`;
res.status(200).send(template)
} else {
console.log('redirected');
res.status(301).redirect('/')
} PHP $context->set('req', new Request(), true);
$context->set('res', new Response(), true); |
Thanks you for helping me.
and in App.php
and in Index.php file, i add
One again, i thank u so much. |
Thanks for help me make react ssr with php.
But i have problem when make it better for me. I add meta tags use react-helmet or react-meta-tags . It change title with my route but when i view source page, Meta tags is not change.
Can you have solution for this problem.
The text was updated successfully, but these errors were encountered: