2017-06-15 59 views
0

工作做出反應路由器3.0.x的,我下面的ENV:經與配置基本名稱與反應路由器,終極版4.0.x的

"react": "^15.4.2", 
"react-redux": "^5.0.3", 
"react-router": "^3.0.2", 
"react-router-redux": "^4.0.8", 

遷移反應路由器4 不是一個選項這個項目。

用下面的配置我的應用程序工作正常(這意味着:我dispatch(push('/foo'))正在努力,執行瀏覽器URL變化一個終極版店@@reouter/LOCATION_CHANGE):

import { Provider } from 'react-redux'; 
import { browserHistory } from 'react-router'; 
import { Router, useRouterHistory } from 'react-router'; 

const history = syncHistoryWithStore(browserHistory, store); 

ReactDOM.render(
    <Provider store={store}> 
    <Router history={history} routes={routes} /> 
    </Provider>, 
    rootEl 
); 

問題開始時,我需要添加一個basename到路由URL。

我發現了一些不同的方法來做到這一點。按照測試我做的一個:

import { Provider } from 'react-redux'; 
import { Router, useRouterHistory } from 'react-router'; 
//import { createHistory } from 'history'; 
import createBrowserHistory from 'history/lib/createBrowserHistory'; 


//const browserHistory = useRouterHistory(createHistory)({ 
// basename: config.historyBasename, 
//}); 

const browserHistory = useRouterHistory(createBrowserHistory)({ 
    basename: config.historyBasename, 
}); 

const history = syncHistoryWithStore(browserHistory, store); 

ReactDOM.render(
    <Provider store={store}> 
    <Router history={history} routes={routes} /> 
    </Provider>, 
    rootEl 
); 

無論配置我試試,我的pushreact-router-redux發稿現在停止工作:我還看到一個瀏覽器URL的變化,但在我的店裏沒有變化。

可能有react-router-redux與上面列出的版本basename一起使用?

+0

https://github.com/reactjs/react-router-redux/issues/414#issuecomment-228582441 – spex

+0

回答你是否可以的最後一個問題,是的。我有它的工作,但你的配置與我的一樣。 –

+0

@DanBalaban d'oh!你的'push'觸發LOCATION_CHANGE? –

回答

0

最後我們發現反應路由器配置沒有問題。

問題出在Route配置中。 path參數前缺少的斜槓導致了該錯誤。