用 browserHistory 替换 hashHistory 时出错:反应
Error while replacing hashHistory with browserHistory : react
我是 React 新手,正在使用 this boilerplate 创建应用程序。
我想使用 browserHistory 而不是 hashHistory,所以我对 /app/index.js
进行了这些更改:
// @flow
import React from 'react';
import ReactDOM from 'react-dom';
import { Provider } from 'react-redux';
import { createStore, combineReducers } from 'redux';
import { Router, browserHistory } from 'react-router';
import { syncHistoryWithStore, routerReducer } from 'react-router-redux';
import routes from './routes';
import configureStore from './store/configureStore';
import './app.global.css';
const store = createStore(
combineReducers({
routing: routerReducer
})
);
const history = syncHistoryWithStore(browserHistory, store);
ReactDOM.render(
<Provider store={store}>
<Router history={history} routes={routes} />
</Provider>,
document.getElementById('root')
);
我收到此警告:
Warning: [react-router] Location "/home/cortana/Projects/JSProjects/gobbledigook/app/app.html" did not match any routes
并且没有显示路由描述的页面。这里缺少什么?我还需要做什么才能删除 hashHistory 并在此应用程序中改用 browserHistory?
看这里,也许你能帮上忙 - https://github.com/chentsulin/electron-react-boilerplate/issues/511
这个答案对您来说可能有点晚了,但如果其他人想知道,请看这里。
如果您想使用 browserHistory 而不是 hashHistory,您需要配置您的服务器,以便它可以处理您传递的 url。这里有一个 link 解释了每一个是如何工作的,它也可以给你一个关于如何配置你的服务器来处理 urls 的线索:https://github.com/ReactTraining/react-router/blob/master/docs/guides/Histories.md
我是 React 新手,正在使用 this boilerplate 创建应用程序。
我想使用 browserHistory 而不是 hashHistory,所以我对 /app/index.js
进行了这些更改:
// @flow
import React from 'react';
import ReactDOM from 'react-dom';
import { Provider } from 'react-redux';
import { createStore, combineReducers } from 'redux';
import { Router, browserHistory } from 'react-router';
import { syncHistoryWithStore, routerReducer } from 'react-router-redux';
import routes from './routes';
import configureStore from './store/configureStore';
import './app.global.css';
const store = createStore(
combineReducers({
routing: routerReducer
})
);
const history = syncHistoryWithStore(browserHistory, store);
ReactDOM.render(
<Provider store={store}>
<Router history={history} routes={routes} />
</Provider>,
document.getElementById('root')
);
我收到此警告:
Warning: [react-router] Location "/home/cortana/Projects/JSProjects/gobbledigook/app/app.html" did not match any routes
并且没有显示路由描述的页面。这里缺少什么?我还需要做什么才能删除 hashHistory 并在此应用程序中改用 browserHistory?
看这里,也许你能帮上忙 - https://github.com/chentsulin/electron-react-boilerplate/issues/511
这个答案对您来说可能有点晚了,但如果其他人想知道,请看这里。
如果您想使用 browserHistory 而不是 hashHistory,您需要配置您的服务器,以便它可以处理您传递的 url。这里有一个 link 解释了每一个是如何工作的,它也可以给你一个关于如何配置你的服务器来处理 urls 的线索:https://github.com/ReactTraining/react-router/blob/master/docs/guides/Histories.md