我正在做一个 i18n 实现。我有我的路线/:locale/rest/of/route
,我想根据加载的语言环境传递字典。在路由配置上这样做会很酷。但我只能考虑在每个容器上这样做。但我的主要不确定性是代码重复。(在每个容器中this.props.dictionary[this.props.route.locale]
)
是一种避免这种代码重复的方法吗?
这是我的配置文件:
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')
)