Skip to content

Commit 9d9d31e

Browse files
authored
Add instructions on <meta> tags
1 parent d803e52 commit 9d9d31e

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

template/README.md

+19
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ You can find the most recent version of this guide [here](https://github.com/fac
2121
- [Adding Custom Environment Variables](#adding-custom-environment-variables)
2222
- [Integrating with a Node Backend](#integrating-with-a-node-backend)
2323
- [Proxying API Requests in Development](#proxying-api-requests-in-development)
24+
- [Adding `<meta>` Tags](#adding-meta-tags)
2425
- [Deployment](#deployment)
2526
- [Now](#now)
2627
- [Heroku](#heroku)
@@ -501,6 +502,24 @@ If the `proxy` option is **not** flexible enough for you, alternatively you can:
501502
* Enable CORS on your server ([here’s how to do it for Express](http://enable-cors.org/server_expressjs.html)).
502503
* Use [environment variables](#adding-custom-environment-variables) to inject the right server host and port into your app.
503504
505+
## Adding `<meta>` Tags
506+
507+
You can edit the generated `index.html` and add any tags you’d like to it. However, since Create React App doesn’t support server rendering, you might be wondering how to make `<meta>` tags dynamic and reflect the current URL.
508+
509+
To solve this, we recommend to add placeholders into the HTML, like this:
510+
511+
```html
512+
<!doctype html>
513+
<html lang="en">
514+
<head>
515+
<meta property="og:title" content="$OG_TITLE">
516+
<meta property="og:description" content="$OG_DESCRIPTION">
517+
```
518+
519+
Then, on the server, regardless of the backend you use, you can read `index.html` into memory and replace `$OG_TITLE`, `$OG_DESCRIPTION`, and any other placeholders with values depending on the current URL. Just make sure to sanitize and escape the interpolated values so that they are safe to embed into HTML!
520+
521+
If you use a Node server, you can even share the route matching logic between the client and the server. However duplicating it also works fine in simple cases.
522+
504523
## Deployment
505524
506525
By default, Create React App produces a build assuming your app is hosted at the server root.

0 commit comments

Comments
 (0)