我嘗試使用react-router-dom 4.0.0庫。但它給我這個錯誤無法讀取未定義的屬性「位置」
Uncaught TypeError: Cannot read property 'location' of undefined
在browserHistore似乎這個問題。在使用react-router 2.x.x之前,一切都很順利。 這是我index.js
import 'babel-polyfill'
import React from 'react'
import { Router, hashHistory } from 'react-router-dom'
import { render } from 'react-dom'
import { Provider } from 'react-redux'
import { configureStore } from './store'
import { routes } from './routes'
const store = configureStore()
render(
<Provider store={store}>
<Router history={hashHistory} routes={routes} />
</Provider>,
document.getElementById('root')
)
這是我的路線
import React from 'react'
import { IndexRoute, Route } from 'react-router-dom'
import App from './containers/App'
import Main from './containers/Main'
import First from './containers/First'
export const routes = (
<Route path='/' component={Main}>
<Route path='/path' component={First} />
<IndexRoute component={App} />
</Route>
)
,也爲服務器端表達我設置獲取配置
app.get('*', function root(req, res) {
res.sendFile(__dirname + '/index.html');
});
謝謝。它幫助了我。 –
它讓我不再問一個問題。非常感謝。但它的'進口{BrowserRouter作爲路由器,路由}從'react-router-dom';'從'react-router-dom''進口{路由器作爲BrowserRouter,路由}' – Jeril
@Jeril固定!謝謝。 –