Last active
July 24, 2019 21:50
-
-
Save prateekbh/09922d11de208c36ee789325e0b697b1 to your computer and use it in GitHub Desktop.
How to get pre-rendered data in `routes` folder components
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { h, Component } from 'preact'; | |
import { Router } from 'preact-router'; | |
import { Provider } from '@preact/prerender-data-provider'; | |
import Home from './routes/home'; | |
import Route66 from './routes/route66'; | |
import Custom from './routes/custom'; | |
import './style.css'; | |
export default class App extends Component { | |
handleRoute = e => { | |
this.currentUrl = e.url; | |
}; | |
render(props) { | |
return ( | |
<Provider value={props}> | |
<div id="app"> | |
<Router url={props.url} onChange={this.handleRoute} {...props}> | |
<Home path="/" /> | |
<Route66 path="/route66" /> | |
<Custom path="/custom" /> | |
</Router> | |
</div> | |
</Provider> | |
); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import './custom.css'; | |
import { withPrerenderData } from '@preact/prerender-data-provider'; | |
const Custom = ({ CLI_PRERENDER_DATA: { myProp } }) => <div>{myProp}</div>; | |
export default withPrerenderData(Custom); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment