i'm doing an i18n implementation. I have my routes like /:locale/rest/of/route
and i want to pass the dictionary depending on which locale is loaded. This would be cool to do it on the routes configuration. But i can only think on doing this on every container. But my main uncertainty is the code duplication. (in each container this.props.dictionary[this.props.route.locale]
)
Is a way to avoid this code duplication?
Here is my config file:
import React from 'react'
import ReactDOM from 'react-dom'
import { Provider } from 'react-redux'
import thunk from 'redux-thunk'
import { Router, Route, IndexRoute, Redirect } from 'react-router'
import createBrowserHistory from 'history/lib/createBrowserHistory'
import { syncReduxAndRouter } from 'redux-simple-router'
import * as containers from './app/app/containers'
import AppUser from './app/app/AppUser'
import AppCompany from './app/app/AppCompany'
import { createStore, applyMiddleware } from 'redux'
import reducers from './app/app/reducers'
const createStoreWithMiddleware = applyMiddleware(
thunk
)(createStore)
const store = createStoreWithMiddleware(reducers)
const history = createBrowserHistory()
syncReduxAndRouter(history, store)
ReactDOM.render(
<Provider store={store}>
<Router history={history}>
<Route path="/:lang" component={AppUser}>
<IndexRoute component={containers.Landing} />
<Route
path="workflow"
component={containers.Workflow} />
<Route
path="register"
component={containers.Register} />
<Route
path="login"
component={containers.Login} />
</Route>
<Redirect from="/" to="/en" />
<Route path="/:lang/company" component={AppCompany}>
<Route
path="inbox"
component={containers.Inbox} />
<Route
path="inbox/:caseId"
component={containers.CaseDetail} />
</Route>
<Redirect from="/company/inbox" to="/en/company/inbox" />
</Router>
</Provider>,
document.getElementById('root')
)