Created
July 28, 2016 21:26
-
-
Save marsch/f77a49cda4f439207aa8f94c60ffa8b4 to your computer and use it in GitHub Desktop.
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 React from 'react'; | |
import { Router, Route, browserHistory, IndexRoute, Redirect, applyRouterMiddleware } from 'react-router' | |
import useScroll from 'react-router-scroll'; | |
import BaseComponent from '../base-component'; | |
import ViewContainer from './view-container'; | |
import ViewManager from './view-manager'; | |
class SiteManager extends BaseComponent { | |
constructor(...args) { | |
super(...args); | |
this.elmIds = {}; | |
this.routesRegistry = {}; | |
this.onGetNextId = this.getNextId.bind(this); | |
} | |
getNextId(elmName) { | |
if (this.elmIds[elmName]) { | |
this.elmIds[elmName] = this.elmIds[elmName] + 1; | |
} else { | |
this.elmIds[elmName] = 1; | |
} | |
return `${elmName}-${this.elmIds[elmName]}` | |
} | |
componentDidMount() {} | |
render() { | |
return ( | |
<Router history={browserHistory} onUpdate={() => { if (window) window.scrollTo(0, 0)}}> | |
<Route path="/" {...this.props} getNextId={this.onGetNextId} component={ViewContainer}> | |
<IndexRoute {...this.props} getNextId={this.onGetNextId} component={ViewManager}/> | |
<Redirect from="index" to="/index.html" /> | |
<Route path='/' {...this.props} getNextId={this.onGetNextId} component={ViewManager}/> | |
<Route path='*' {...this.props} siteConfig={this.props.initState.siteConfig} getNextId={this.onGetNextId} component={ViewManager}/> | |
</Route> | |
</Router> | |
); | |
} | |
} | |
export default SiteManager; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment