# react-easy-seo

> A Creative Solution For Your React Seo Problems.

Latest version **1.0.6** (published 2021-12-25) · MIT license · 0 weekly downloads

## Install

```sh
npm install react-easy-seo
pnpm add react-easy-seo
yarn add react-easy-seo
bun add react-easy-seo
```

Provides the command `react-easy-seo`.

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.6 |
| Published | 2021-12-25 |
| First published | 2021-12-22 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Unpacked size | 158 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | github.com/ahanikotb |
| Maintainers | ahanikotb |
| Keywords | react-seo, react-easy-seo, title, meta, tags, react |

## Links

- npm: https://www.npmjs.com/package/react-easy-seo
- Repository: https://github.com/ahanikotb/react-easy-seo
- Homepage: https://github.com/ahanikotb/react-easy-seo#readme
- Issues: https://github.com/ahanikotb/react-easy-seo/issues
- npm.io page: https://npm.io/package/react-easy-seo

## Dependencies (2)

- [fs-extra](https://npm.io/package/fs-extra.md) ^10.0.0
- [react-helmet](https://npm.io/package/react-helmet.md) ^6.1.0

## Alternatives

- [mobx-react](https://npm.io/package/mobx-react.md) — 2.8M weekly downloads
- [rc-tree](https://npm.io/package/rc-tree.md) — 2.6M weekly downloads
- [@react-oauth/google](https://npm.io/package/@react-oauth/google.md) — 1.3M weekly downloads
- [@wagmi/connectors](https://npm.io/package/@wagmi/connectors.md) — 877.0K weekly downloads
- [vee-validate](https://npm.io/package/vee-validate.md) — 836.4K weekly downloads

## Recent versions

- 1.0.6 (latest) — 2021-12-25
- 1.0.5 — 2021-12-25
- 1.0.4 — 2021-12-22
- 1.0.3 — 2021-12-22
- 1.0.2 — 2021-12-22
- 1.0.1 — 2021-12-22
- 1.0.0 — 2021-12-22

## README

# react-easy-seo

# a npm package that provides a  creative solution for react seo without ssr or preload relies on react-router-dom and react-helmet

# Installation
npm install -g react-easy-seo


# Setup


1- create a sitemetadata.json in project root/src folder
![sitemetadata json sample](https://raw.githubusercontent.com/ahanikotb/react-easy-seo/main/samplejson.png)

2- add "postbuild":"react-easy-seo" in the scripts section in your package.json .  
"scripts":{
    .....   
    "postbuild":"react-easy-seo"   
  }.   
  
3-Add ReactHelmet to App.js
   - install react-helmet and react-router-dom
   - Use the sitemetada.json  as a source for dynamic metadata as well
    
   - import useLocation
        `import {useLocation} from 'react-router-dom'`

   - get location and make sure it has '/' at the end
     
     `var currentLocation = location.pathname

       if (currentLocation[currentLocation.length -1 ] !== "/"){
        currentLocation = currentLocation.concat("/")
                      }`
     
   - add this in your Component
    `   <Helmet>
            <meta name='title' content={siteMetadata[currentLocation]['title'] }/> 
            <meta name="description" content={siteMetadata[currentLocation]['description']}/> 
            <title> {siteMetadata[currentLocation]['title']}</title>
        </Helmet>`

     
  
 
4-run your react build normally and the output will be in './output'

# How it Works 
react-easy-seo transforms your react single page application to the traditional html folder structure using the routes provided in the sitemap.json file you make.

the json is structured as follows:

key     value 
route   {metadataname : metadatacontent}

example:{"/":{"title":"react-easy-seo","description":"react-easy-seo is the best way to handle react seo"}}
<br/>
which is converted to =>

`
"<meta name="title" content="react-easy-seo"></meta>"
"<meta name="description" content="react-easy-seo is the best way to handle react seo"></meta>"
"<title>react-easy-seo</title>"
`

so for each route you can have as many metadata as you want.
another cool feature is having an article metadataname in the route object 

{"/":{"article":"react-easy-seo is the best way to handle react seo"}}
this is converted to => 
`<p>react-easy-seo is the best way to handle react seo</p>`
and is added to the root div so its replaced as soon as your app loads but can really help with seo.

---
_Source: https://npm.io/package/react-easy-seo · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
