1.0.0 • Published 6 years ago

@elricb/wordpress-react-router v1.0.0

Weekly downloads
-
License
ISC
Repository
github
Last release
6 years ago

Wordpress-React-Router

TODO setup a test page (build-location) and test wordpress site to point to.

Webpack

I'm partial to webpack code splitting, so I use webpack System.import in the examples. Reinterpret to suit your different build system needs.

WordpressRouter

Loads markup from Wordpress Page. If an override component exists, loads component and passes in Wordpress Page json through props.

//output from wp-json (minified/saved)
import siteConfig from 'config/site.json';
import MyContainer from 'somewhere/my-container';

let wordpressUrl = 'http://mysite/wordpress-path/wp-json',
    wordpressData = new WordpressData(wordpressUrl, siteConfig),
    wordpressPage = window.location.pathname.split('/')[1] || '',
    componentPromise = import('./route/' + wordpressPage + '/index.jsx');

return (
    <MyContainer>
        <WordpressRouter
            wordpressData={wordpressData}
            wordpressPage={wordpressPage}
            wordpressComponent={componentPromise}
        />
    </MyContainer>
);

Setup

Wordpress

You'll need Wordpress installed with plugin REST API 2 or greater.

Webserver

Your server will need to interpret paths and point them back to your React index page.

Sample

tbd