我尝试使用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固定!谢谢。 –