-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRoutedContainer.tsx
51 lines (42 loc) · 1.19 KB
/
RoutedContainer.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
// Copyright (c) 2019 Gonzalo Müller Bravo.
// Licensed under the MIT License (MIT), see LICENSE.txt
import {Container} from 'flux/utils'
import React, { Component } from 'react'
import { RouteComponentProps, Switch } from 'react-router'
import { BrowserRouter, Route } from 'react-router-dom'
import MainComponent from '../front/MainComponent'
import SecondaryComponent from '../front/SecondaryComponent'
import MainStoreState from './MainStoreState'
import mainStore from './singletons/mainStore'
class RoutedContainer extends Component<{}, MainStoreState> {
static getStores() {
return [mainStore]
}
static calculateState(): MainStoreState {
return {
main: mainStore.getState()
}
}
renderMainComponent = (routeProps: RouteComponentProps) => {
return (
<MainComponent {...this.state.main}/>
)
}
render() {
return (
<BrowserRouter>
<Switch>
<Route
path='/secondary'
component={SecondaryComponent}
/>
<Route
path='/'
render={this.renderMainComponent}
/>
</Switch>
</BrowserRouter>
)
}
}
export default Container.create(RoutedContainer)