netlify-cms-react-starter/src/App.js
2017-10-14 16:04:09 +10:00

60 lines
1.8 KiB
JavaScript

import React, { Component } from 'react'
import { BrowserRouter as Router, Route, Switch } from 'react-router-dom'
import Helmet from 'react-helmet'
import ScrollToTop from './components/ScrollToTop'
import Home from './views/Home'
import About from './views/About'
import Contact from './views/Contact'
import NoMatch from './views/NoMatch'
import Nav from './components/Nav'
import GithubCorner from './components/GithubCorner'
import ServiceWorkerNotifications from './components/ServiceWorkerNotifications'
import globalStyles from './globalStyles'
import data from './data.json'
export const siteTitle = 'HyperStatic'
class App extends Component {
state = {
data
}
componentWillMount () {
globalStyles()
import('./netlifyIdentity')
}
getDocument = (collection, name) =>
this.state.data[collection] && this.state.data[collection].filter(page => page.name === name)[0]
getDocuments = (collection) => this.state.data[collection]
render () {
return (
<Router>
<div>
<ScrollToTop />
<ServiceWorkerNotifications />
<GithubCorner url='https://github.com/Jinksi/hyperstatic' />
<Helmet titleTemplate={`${siteTitle} | %s`} />
<Nav />
<Switch>
<Route path='/' exact
render={(props) => <Home page={this.getDocument('pages', 'home')} {...props} />}
/>
<Route path='/about/' exact
render={(props) => <About page={this.getDocument('pages', 'about')} {...props} />}
/>
<Route path='/contact/' exact
render={(props) => <Contact page={this.getDocument('pages', 'contact')} {...props} />}
/>
<Route component={NoMatch} />
</Switch>
</div>
</Router>
)
}
}
export default App