2017-04-25 4 views
2

私はリアクションを学んでおり、リアクタをリアルータで使用したいと考えています。 プロバイダがルータ内かその反対側で問題になりますか?ルータとプロバイダの継承

<Provider store={store}> 
    <Browser> 
    // routes 
    </Browser> 
</Provder> 

または

<Browser>  
    <Provider store={store}> 
    // routes 
    </Provder> 
</Browser> 

一見、私は両方の方法を使用することができます。何が良くなります。何か不足していますか?

答えて

2

ルーティングの状態を店舗と同期するかどうかによって異なります。たとえば、react-router-reduxを使用している場合は、最初にProviderRouterを設定します。ドキュメントから

import React from 'react' 
import ReactDOM from 'react-dom' 
import { createStore, combineReducers } from 'redux' 
import { Provider } from 'react-redux' 
import { Router, Route, browserHistory } from 'react-router' 
import { syncHistoryWithStore, routerReducer } from 'react-router-redux' 

import reducers from '<project-path>/reducers' 

// Add the reducer to your store on the `routing` key 
const store = createStore(
    combineReducers({ 
    ...reducers, 
    routing: routerReducer 
    }) 
) 

// Create an enhanced history that syncs navigation events with the store 
const history = syncHistoryWithStore(browserHistory, store) 

ReactDOM.render(
    <Provider store={store}> 
    { /* Tell the Router to use our enhanced history */ } 
    <Router history={history}> 
     <Route path="/" component={App}> 
     <Route path="foo" component={Foo}/> 
     <Route path="bar" component={Bar}/> 
     </Route> 
    </Router> 
    </Provider>, 
    document.getElementById('mount') 
)