Skip to content

Instantly share code, notes, and snippets.

@marsch
Created July 28, 2016 21:26
Show Gist options
  • Save marsch/f77a49cda4f439207aa8f94c60ffa8b4 to your computer and use it in GitHub Desktop.
Save marsch/f77a49cda4f439207aa8f94c60ffa8b4 to your computer and use it in GitHub Desktop.
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