每當我在本地使用browserHistory我沒有問題,但是當我測試它之前我運送它,我得到一個空白頁面的錯誤。所以當我用hashHistory替換browserHistory時,一切正常,但我失去了漂亮的url。反應路由器browserHistory在本地工作,而不是生產
Uncaught SecurityError: Failed to execute 'replaceState' on 'History': A history state object with URL 'file:///Users/somefile/work/someproject/index.html' cannot be created in a document with origin 'null' and URL.
const Routes = (
<Router history={browserHistory}>
<Route path="/" component={Login} />
<Route path="/content" component={App} >
<Route path="/component1" component={component1} />
<Route path="/component2" component={component2} />
<Route path="/component3" component={component3} />
</Route>
</Router>
);
我index.js
const createStoreWithMiddleware = applyMiddleware(ReduxPromise)(createStore);
const store = createStoreWithMiddleware(reducers);
ReactDOM.render(
<Provider store={store}>
{Routes}
</Provider>,
document.querySelector('.react-internal')
)
在我app.js
export default class App extends Component {
render() {
return (
<div>
<Header />
<div className="container-fluid">
{this.props.children}
</div>
</div>
);
}
}
和我的WebPack文件
var webpack = require('webpack');
module.exports = {
devtool:'source-map',
entry: [
'./src/index.js',
],
output: {
path: __dirname,
publicPath: '/',
filename: 'bundle.js'
},
module: {
loaders: [
{
exclude: /node_modules/,
loaders: ['react-hot','babel']
},
{ test: /\.css$/, loader: "style!css" },
{
test: /\.(jpe?g|png|gif|svg)$/i,
loaders: [
'file?hash=sha512&digest=hex&name=[hash].[ext]',
'image-webpack?bypassOnDebug&optimizationLevel=7&interlaced=false'
]
}
]
},
resolve: {
extensions: ['', '.js', '.jsx']
},
devServer: {
port:8080,
historyApiFallback: true,
contentBase: './'
}
};
的(http://stackoverflow.com [產地空不被訪問控制允許來源允許]可能的複製/ questions/8456538/origin-null-is-not-access-access-control-allow-origin) – Chris
當你在本地測試時,你是通過網絡服務器運行還是僅僅點擊HTML文件? – krs
當我在本地運行它時,我在webpack dev服務器上運行它。在我運行webpack並捆綁它之後,我通過單擊index.html文件來測試它 – caffeinescript